Issue with optional Core Data relationship using NSPersistentCloudKitContainer
Asked Answered
S

0

1

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?

Selfsufficient answered 25/5, 2020 at 10:48 Comment(3)
I could also reproduce the issue in apples demo project for NSPersistentCloudKitContainer. Instead of deleting attachments, I just removed them from the post. They still have the post assigned in iCloud Dashboard and relation got synced back on next change.Selfsufficient
Not the only one with this issue btw, see: #57471136Selfsufficient
Also posted on Apple Developer Forum: forums.developer.apple.com/forums/thread/649033Selfsufficient

© 2022 - 2024 — McMap. All rights reserved.