Reputation: 10378
THE SETUP: I have an app that uses iCloud + Core Data. It contains a switch to turn iCloud on/off, and when this happens, data is migrated to/from local/iCloud stores.
THE PROBLEM: iCloud on. Add Core Data object. Switch to local. Switch back to iCloud. Now there are two identical objects.
WHAT I'D LIKE TO HAPPEN: I'm assuming that this is expected, and that I will need to de-duplicate when I migrate a local store to an iCloud store (correct me if this isn't expected). I can't figure out where or how the normal way to de-duplicate is. Where in my code should I perform de-duplication, and roughly what should the code look like?
Upvotes: 2
Views: 739
Reputation: 3592
You would usually deduplicate the data when you receive the NSPersistentStoreDidImportUbiquitousContentChangesNotification
notification, and you have merged the changes into your context. After merging, go through the data and dedupe.
Here is a good tutorial on deduping: http://www.atomicbird.com/blog/icloud-complications-part-2
Deduplication is one of the poorer design aspects of Core Data + iCloud in my view. Other sync solutions, like Wasabi Sync and Ensembles, allow you to provide global identifiers as an alternative to deduplication. I find it a cleaner solution. (Disclosure: I am the developer of Ensembles.)
Upvotes: 5