mluisbrown / iCloudCoreDataStack

A persistence stack for using Core Data with iCloud Sync in iOS7
126 stars 11 forks source link

Migration Issues with duplicate entries #5

Open HaFondEcran opened 10 years ago

HaFondEcran commented 10 years ago

Hello,

I have an already existing core data apps synchonized by dropbox and I want to migrate on iCloud (with iCloudCoreDataStack). And have 2 devices ( iPhone and iPad) with the same data inside.

I update the ipad apps to the new apps with icloud, everything work fine and synchonisation works.

When I update the iphone, all core data entries are duplicates, I under why : I merge and existing store with the icloud store with the same information. If you have and idea to avoid that ...

mluisbrown commented 10 years ago

Hi, You need to do your own de-duplication either when you migrate a non-iCloud store to iCloud and also when you merge changes that have occurred on another device. The de-duplication algorithm you use will depend on your data.

Core Data doesn't know that your records are the same, it creates a unique GUID type key for every record that is created. Even two records with identical data will have a different Core Data ID. When store migration or data merges happen you have to have a method that determines, based on a unique key that is suitable for your data, which records are duplicates and can therefore be removed.

I hope that helps.