Hi,
On iOS 14 beta 1-3 I was happily using a constraint on several entities in NSPersistentCloudKitContainer.
The part of the app using this was essentially an RSS reader - two different devices were independently fetching news and no duplicates due to the constraints.
Now on iOS14 beta 4 I'm receiving "CloudKit integration does not support unique constraints", which means I've had to remove the constraints..
Now the app is subject to CloudKit sync vs RSS import timing issues.. if CloudKit syncs after the RSS import then there are "duplicate" items.
What's the "workaround" for this please? It really should just work.
Thanks,
Andy
On iOS 14 beta 1-3 I was happily using a constraint on several entities in NSPersistentCloudKitContainer.
The part of the app using this was essentially an RSS reader - two different devices were independently fetching news and no duplicates due to the constraints.
Now on iOS14 beta 4 I'm receiving "CloudKit integration does not support unique constraints", which means I've had to remove the constraints..
Now the app is subject to CloudKit sync vs RSS import timing issues.. if CloudKit syncs after the RSS import then there are "duplicate" items.
What's the "workaround" for this please? It really should just work.
Thanks,
Andy
Unfortunately this was never supported, and fails in byzantine ways, so it produces a clear error up front now.
You can use the persistent history to de-dupe whenever you import new changes. You can be informed of this from observing the NSPersistentStoreCoordinator posting NSManagedObjectContextDidSaveObjectIDsNotification, or the new NSPersistentCloudKitContainerEvent APIs with NSPersistentCloudKitContainerEventChangedNotification
Alternatively, you can use two persistent stores, one local and one CloudKit. You'll put the entities in different Configurations and add them to the same NSPersistentStoreCoordinator. The entities in the local configuration can use any Core Data features including unique constraints. You'd use persistent history and the notifications to drive importing and exporting between the two store files. This is more customizable but obviously a considerable amount of work.
You can use the persistent history to de-dupe whenever you import new changes. You can be informed of this from observing the NSPersistentStoreCoordinator posting NSManagedObjectContextDidSaveObjectIDsNotification, or the new NSPersistentCloudKitContainerEvent APIs with NSPersistentCloudKitContainerEventChangedNotification
Alternatively, you can use two persistent stores, one local and one CloudKit. You'll put the entities in different Configurations and add them to the same NSPersistentStoreCoordinator. The entities in the local configuration can use any Core Data features including unique constraints. You'd use persistent history and the notifications to drive importing and exporting between the two store files. This is more customizable but obviously a considerable amount of work.