Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot use an empty list to initialize a new field #11

Open
huanglins opened this issue Jul 28, 2023 · 3 comments
Open

cannot use an empty list to initialize a new field #11

huanglins opened this issue Jul 28, 2023 · 3 comments

Comments

@huanglins
Copy link

Do I have an optional array type field such as [Int]? How to fix this error

@insidegui
Copy link
Owner

@huanglins Can you share some code snippets of what you're trying to achieve?

@huanglins
Copy link
Author

I probably have a model of this

struct Person {
    var name: String
    var scores: [Int]?
}

let person = Person(name: "v")

sync person
  1. When scores is empty, initializing a CKRecord is not possible.
    cannot use an empty list to initialize a new field

  2. 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.

@insidegui
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants