swiftcouchbasecouchbase-lite

Converting Swift array to Couchbase lite ArrayObject


I'm trying to write a Swift string array, [String], to a Couchbase lite 2.7 document. MutableDocument has a method setArray(value: ArrayObject?, forKey: String). How can I convert the swift array to an ArrayObject?


Solution

  • ArrayObject has a mutable counterpart MutableArrayObject that has an initialiser that takes an Array<Any>?. Here's an example:

    let swiftArray = ["foo", "bar"]
    let CBLArray = MutableArrayObject.init(data: swiftArray)
    print(CBLArray.toArray())