Search code examples
iosswiftcore-datadata-migrationnspersistentcloudkitcontainer

Lightweight CoreData Migration with CloudKit


Does Core Data handle simple data-model additions like a new attribute w/out any further "help" from me? In my case, I have an app that uses Core Data for varius things related to a users profile. I have an existing data-model entity called Profile that I want to add 2 new attributes to:

hasPublished: Boolean

lastDetail: String

So, does this cover my case? I'm not re-naming anything, just adding.

One more caveat, I'm using a NSPersistentCloudKitContainer as info can be shared across the users devices.


Solution

  • Yes it can handle, but there is some little work from your side.

    1. You need to create new version of Core Data model.
    2. Call initializeCloudKitSchema() so changes are uploaded to CloudKit.
    3. Don't forget to deploy changes to production from CloudKit dashboard.
    4. Remove initializeCloudKitSchema() when deploying your app to AppStore.