Reputation: 518
Integrating NSPersistentCloudKitContainer is quite easy and works fine when user add data after synchronization is implemented. However, if users already added the same data on different devices and syncing will be enabled on an update, all data are duplicated on all devices.
Is there a ways to set an own identifier for your own data type to prevent duplication?
Upvotes: 4
Views: 694
Reputation: 685
The duplication of data is just the "normal" way of how NSPersistentCloudKitContainer works. If we have some rules that want to apply to the data, we have to do that manually.
let's say, if we added some data at the Apps first launch, using NSPersistentCloudKitContainer, chances are the user has a different device and the same set of data is added, hence making 2 sets of the same data added to the store.
To avoid this, we can give a UUID field to each preload data, fetch those with the same UUID and remove the duplicated one.
I have answer a similar question recently and hope that can give you a little help (And hope I didn't misunderstand your question):
https://stackoverflow.com/a/66908250/11207700
Upvotes: 2