drewmccormack / ensembles

A synchronization framework for Core Data.
MIT License
1.63k stars 131 forks source link

How to detect if some iCloud data is available at first app start #219

Closed andepopande closed 8 years ago

andepopande commented 8 years ago

I am using your great framework in my TODO app and I have a set of predefined categories / items that I read from a csv file and save it to Core Data every time the app is being installed and launched for the first time. If I have done this on one device and enabled iCloud sync, all the prefilled data will go to other devices. Now if I install the app on another device I am thinking about not prefilling (or asking the user if he wants to prefill) the database with the default categories / items as soon as I know that there is data in Ensembles available. I wonder if there is an easy way to find out if there is anything available inside iCloud, so that I do not have to start populating the database every time the app is being installed. Can you give me a hint how to do that? Thanks and all the best! Andy

drewmccormack commented 8 years ago

Hi Andy,

I’m afraid this approach is accident prone. You can never really know if there is data in iCloud. It might not show up right away, and even if it worked most of the time, there is always the chance one device is uploading just when the other turns up. Then you have a problem.

A better way to handle this is to use global ids. Assign the ‘launch data’ fixed global ids, which are the same on each device. Ensembles will then merge them as if they really are the same objects, even if they were created separately.

Kind regards, Drew

On 01 Mar 2016, at 10:06, Andreas Krawczyk notifications@github.com wrote:

I am using your great framework in my TODO app and I have a set of predefined categories / items that I read from a csv file and save it to Core Data every time the app is being installed and launched for the first time. If I have done this on one device and enabled iCloud sync, all the prefilled data will go to other devices. Now if I install the app on another device I am thinking about not prefilling (or asking the user if he wants to prefill) the database with the default categories / items as soon as I know that there is data in Ensembles available. I wonder if there is an easy way to find out if there is anything available inside iCloud, so that I do not have to start populating the database every time the app is being installed. Can you give me a hint how to do that? Thanks and all the best! Andy

— Reply to this email directly or view it on GitHub https://github.com/drewmccormack/ensembles/issues/219.

andepopande commented 8 years ago

Thanks for your fast answer, Drew. I also thought that this would be error prone, that's why I just prefilled the data on every device on first start. I already use fixed global ids for the prefilled data. But when a user then deletes some of the prefilled data because he will never use it and then installs the app again, those deleted items will be available again, am I right?

By the way: the global IDs for the prefilled data is just something like "item_trousers" or "item_shirts". I the user then adds new items to his todo list, should the ID also be something like "item_mynewitem" or should I assign a UUID for every user generated data?

drewmccormack commented 8 years ago

Thanks for your fast answer, Drew. I also thought that this would be error prone, that's why I just prefilled the data on every device on first start. I already use fixed global ids for the prefilled data. But when a user then deletes some of the prefilled data because he will never use it and then installs the app again, those deleted items will be available again, am I right? Not necessarily. When the app leeches, it imports the local store. This is treated as happening far back at the beginning of time, because we have no timestamps for that data. So if you deleted on another device, those deletions will probably remove the items even on the second device after you merge.

If you really want to keep the data, you would have to sync first, and then add the data. That would then definitely override the deletions.

IMO, if a user deletes some data, they want it gone. So the behavior you gets seems fine to me.

By the way: the global IDs for the prefilled data is just something like "item_trousers" or "item_shirts". I the user then adds new items to his todo list, should the ID also be something like "item_mynewitem" or should I assign a UUID for every user generated data?

For all the new data, I would use UUIDs, not anything specially prepared. You only need the special ids when you are forcing objects on different devices to be seen as the same object.

Kind regards, Drew