CloudKitCodable
CloudKitCodable copied to clipboard
cannot use an empty list to initialize a new field
Do I have an optional array type field such as [Int]? How to fix this error
@huanglins Can you share some code snippets of what you're trying to achieve?
I probably have a model of this
struct Person {
var name: String
var scores: [Int]?
}
let person = Person(name: "v")
sync person
-
When scores is empty, initializing a CKRecord is not possible.
cannot use an empty list to initialize a new field
-
Once a value has been set for an optional property and it has been synced to iCloud, it cannot be set back to nil and synced to iCloud again. It will always sync with the iCloud value.
func encode<T>(_ value: T, forKey key: Key) throws where T : Encodable {
Values should not be set for fields that cannot be nil.
The second issue is more severe.
cannot use an empty list to initialize a new field
This error sounds like you're attempting to initialize a new field for a record in the development environment, which also defines its schema. When that's the case, then there must be some sort of value to inform the CloudKit servers what type of list you're trying to create, since it's a brand new field that the servers don't know about.
I don't think this would be a problem for existing record fields.