Reputation: 1469
My app uses Core Data and iCloud according to Apples latest docs and it works well. What I do not manage/understand is the following:
When the app gets installed, the database will be set up and some initial data will be filled. This works fine for the 1st device.
Once the database is set up in Core Data and the app is going to be installed on a 2nd device (same iCloud account) I need to avoid that the initial data get loaded again. So my idea is, how can I figure out, whether or not the database is already available in iCloud?
I searched a lot and found many discussions, but not at least one solution which fits to the iOS 7 and 8 (Beside the possibility to delete afterwards the duplicate records which I do not want).
Please let me know what you think, any suggestion (or link I haven't found) is highly appreciated!
Upvotes: 3
Views: 131
Reputation: 70976
You can't just set a boolean value to check for initial data, because the boolean value also needs to sync and you might not get it in time. You also can't check for the initial data, because it also needs to sync and might not arrive in time.
But there are a couple of possibilities.
Put the initial data in a separate persistent store file which is not synced. You can have multiple store files, and you can add them all to your persistent store coordinator. Put the initial data in one store file that is not synced and put all the other data in a separate file that is synced. Since the initial data won't sync, there won't be any duplicates. You can't have relationships from one store file to another one, but you can use fetched properties to get something similar.
Keep putting all the data in the same file, but filter out duplicates. With everything in one place, duplicates are inevitable, but you can deal with the problem. You end up waiting until the duplicates appear, finding them, and removing them. It's kind of annoying to need to do this, but it's really the only way if you put everything in the same persistent store. I described the process a while ago in a blog post at my site which goes into detail on how to do this efficiently.
Upvotes: 1