ed94133
ed94133

Reputation: 1595

Core Data, iCloud, and stock objects

I'm updating a local Core Data-driven app to support iCloud. One challenge I anticipate is around what I'm calling "stock objects" -- seed data the app provides at first launch that 99% of users will customize.

Stock Objects

Item A
Item B

Customized Objects

Tomatoes
Potatoes

If the user then launches the app for the first time on a new device, I think the default behavior would be for the re-creation of the stock objects which would get merged with the customized objects from the iCloud persistent store (Item A, Item B, Tomatoes, Potatoes), resulting in a messy user experience.

One approach might be to check for iCloud data synchronously at first launch, and if it exists, not create the stock objects. But still, the user could be offline on first launch, and then on second launch, the same undesirable merge of local stock objects with iCloud custom objects would happen.

Are there ways to add logic to iCloud merges, so that the arrival of customized objects from the cloud (Tomatoes and Potatoes) can signal me to delete local stock objects (Item A and Item B) before they get beamed up?

Thanks!

Upvotes: 2

Views: 523

Answers (2)

ed94133
ed94133

Reputation: 1595

I'm not sure if this is the best approach, but this is what I'm doing:

  1. When the user elects to enable iCloud, I check if their iCloud directory is empty.
  2. If so, no problem; I migrate the database to a new local store that has iCloud options enabled so that all existing data moves to the cloud.
  3. If not, I check if the local database is empty. If it is, I wipe out all the stock objects and take everything from the cloud. If it isn't, I tell the user currently the app can't merge a local database with an iCloud database, and ask them to delete their data (or reinstall), thus sidestepping this problem.

Upvotes: 0

Mundi
Mundi

Reputation: 80271

Why don't you just avoid this by not providing seed objects? Simply prompt the user through the UI to enter his own objects on first launch. Ask, if she has used the app before and explain that it might pay to wait to sync from iCloud before recreating the objects.

Upvotes: 0

Related Questions