CBLModel array property of custom objects in Swift

class Apple: CBLModel {
@NSManaged var array: [CustomObject]?

class CustomObject: NSObject, CBLJSONEncoding {}

How to encode a CBLModel class with an an array property of custom objects in Swift?

CBLModel can’t tell what type of object an array property holds — in Swift it’s part of the type declaration, but the runtime metadata only says it’s NSArray.

So if it’s a custom class, you have to tell CBLModel what class it is by adding a method that returns the class. See the “Array element types” section of the CBLModel guide.

1 Like