Best Way to Migrate Core Data iCloud App to CloudKit

I am seriously thinking that I had better start working on migrating my existing core data iCloud app to CloudKit. I have some thoughts about it from a process standpoint. I guess my big question is how to migrate the iCloud store to the local store. Would I use the NSMigrationManager for this? It seems the way to go.


1. User is using iCloud

Migrate iCloud core data store to local store. Would migrate be the method?

Create CKRecords for each entity and upload to private database

Subscribe to CK changes and update core data store as appropriate based on changes.

2. User is using local storage

Give user option to use CloudKit

if user agrees to use CloudKit

Create CKRecords for each entity and upload to private database

Subscribe to CK changes and update core data store as appropriate based on changes.

Perhaps it's best to use NSPersistentStoreCoordinator method func migratePersistentStore(_ store: NSPersistentStore, to URL: URL, options: [AnyHashable : Any]? = nil, withType storeType: String) throws -> NSPersistentStore

Accepted Answer

Yes, you are looking for:


- (NSPersistentStore *)migratePersistentStore:(NSPersistentStore *)store
                                        toURL:(NSURL *)URL
                                      options:(NSDictionary *)options
                                     withType:(NSString *)storeType
                                        error:(NSError **)error


Make sure that you don't have the ubiquity options in the options dictionary when you make the call, otherwise we'll attempt to ubiquitize the migrated store.

Be aware that certain features of you managed object model may be incompatible with CloudKit (required relationships for example), your mechanism of syncing changes with CloudKit should take this in to account when it builds your CKRecord graph.

Thank you for confirming my suspicion. Understood about differeneces between core data and CloudKit.

Best Way to Migrate Core Data iCloud App to CloudKit
 
 
Q