问题
I am using NSPersistentCloudKitContainer, not sure if that's the cause of my issue or CloudKit generic behaviour. The sync setup works fine so far. I am now adding a new feature, causing some an issue:
I have an entity Item, which can be put in a Group. Relation in CD is to-one and optional. Works fine on device: I can set and remove group, everything is persisted.
But CloudKit just ignores when I remove the group. It does not complain, just ignores it. No matter if remove happens from Item, Groups or both sides. On next download it’s back in a group. Is it just a bug in NSPersistentCloudKitContainer? It’s possible to nil fields on CloudKit records, right?
What I see in CloudKit dashboard: • Group field on Item is of type String. • A fresh Item record, never assigned to a group, does not have the group field. • As soon as it gets a group field, I can’t get rid of it. Emptying the value causes to crash.
When I get the CloudKit record on device, it does not even have the group field. So I can't manually reset it. It only shows the Group field in the CloudKit dashboard. I guess the container handles the relationship internally and only maps it during sync.
Is there any way to properly handle this?
来源:https://stackoverflow.com/questions/62000858/issue-with-optional-core-data-relationship-using-nspersistentcloudkitcontainer