I've managed to get my existing core data app to work with iCloud. After days of study, it was actually surprisingly simple. It seems that 3 things are essential:
to add an entitlements file (in recent Xcode, this can be done using by selecting the target, select "Summary pane", scroll down, check enable entitlements"
to add the correct options while adding the persisten store, in my case
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
// other options
@"<arbitrary name>", NSPersistentStoreUbiquitousContentNameKey,
iCloudURL, NSPersistentStoreUbiquitousContentURLKey,
nil]
where
NSURL * iCloudURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
The `nil' here indicating that information from the Entitlements.plist file is used.
Actually, at the moment I am not sure this last step is crucial for development---i've enabled another app without this last step and it seems to work.
Anyhow, I've noticed that two existing core data bases of the same app on different iDevices will synchronise new entries to the core data stack, but will not automatically sync the existing records.
One way of syncing data from device A to B is to delete the existing core data database on B, and then restart the app on B. However, this is not a proper merge.
Does anybody know a way to merge two existing core data databases on different apps at the moment the apps are upgraded to use iCloud support, i.e., use the options above and all that?
Thanks
Rules can be set up in the dashboard: CloudKit has a lot of tabs. Summary: Firebase can be immediately accessed without authentication but also provides the flexibility to define your own rules. CloudKit is probably more secure and can provide a seamless experience for your users too, but only if they are using iOS.
The next time you need to store data, you should have a better idea of your options. Core Data is unnecessary for random pieces of unrelated data, but it's a perfect fit for a large, relational data set. The defaults system is ideal for small, random pieces of unrelated data, such as settings or the user's preferences.
Overview. The CloudKit framework provides interfaces for moving data between your app and your iCloud containers. You use CloudKit to store your app's existing data in the cloud so that the user can access it on multiple devices. You can also store data in a public area where all users can access it.
Core Data owns the record ID for all of the objects that it creates in CloudKit. And, for each one, we will generate a simple UUID to use as its record name. When the Record Name is combined with a zone identifier you get a CKRecord ID. At the bottom, you'll see how Core Data manages type information.
Maybe this helps: https://gist.github.com/1475162 (by @steipete)
I have not done it, but when saving to the iCloud there is high risk for conflicting information if the data has also been updated or exists on another device. If the conflicts are not properly resolved then the flow between the two devices will not occur properly. Resolving the conflicts can be complicated but the simplest would be to just let the most recent win. Apple has conflict handling procedures that get triggered when saving to overwrite to the ubiquitous store identifies a conflict.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With