Reputation: 505
What is the best way to migrate from CoreData to CloudKit and keep all user's data?
I would like to retire Core-Data and replace it with CloudKit but users have tons of important data and it should be migrated somehow. Also lots of classes are working with CoreData entities and they shouldn't be affected (except CRUD operations). Didn't find any straightforward guidelines for that.
My draft solution:
-check if user has CoreData
-load all CoreData objects in memory
-write them to cloud
-remove CoreData file
Is it something that will work as expected?
It is okay to use classes inherited from NSManagedObject after Core-Data removal? Could it cause any side-effects?
Upvotes: 3
Views: 1676
Reputation: 3202
For anyone finding this since WWDC19, CloudKit CoreData sync is now offered by Apple.
The core step to use this technology is to switch from NSPersistentContainer
to NSPersistentCloudKitContainer
There are some additional steps you can take to allow background syncing.
Full details can be found here: https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit
I have also found this article to be an excellent reference:
Upvotes: 9