2

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.

TheTwoNotes
  • 453
  • 3
  • 15

1 Answers1

4

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.
Stamenkovski
  • 959
  • 1
  • 6
  • 10
  • What does `initializeCloudKitSchema()` do? – christophriepe May 10 '21 at 13:15
  • https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3343548-initializecloudkitschema – Stamenkovski May 11 '21 at 19:01
  • Thanks for the answer. However, I already found this but it didn't fully explain to me what this statement is fore. It would be great if you could describe it shortly. – christophriepe May 11 '21 at 20:09
  • initializeCloudKitSchema is creating all the “tabels” CoreData models and their properties to respective CKRecords on CloudKit dashboard. – Stamenkovski May 11 '21 at 21:09
  • 1
    Thanks for the Explanation. But I am using CloudKit *(with `NSPersistentCloudKitContainer`)* a while now and never added this Method. The CloudKit Scheme however did get created. Is this maybe turned on by default? – christophriepe May 11 '21 at 21:13
  • 1
    Well it is good practice to call the method, you can see if it's successfully created or some error occurred in creating your schema – Stamenkovski May 13 '21 at 09:17
  • So, it seems to be simple. I also want to add one attribute to my CloudKit Core Data Scheme. I just wonder (and worry), would it affect the users of old version of the app? Would their data be in safe and continue to be in sync after deploying of upgraded Scheme to Production? I mean, is it supposed that they will continue to use the old version of the app just like if there is no additional attribute in Entity? – mosariot Aug 28 '22 at 14:26
  • Everything will be safe, the new record does not existing in the old schema so its ignored. – Stamenkovski Aug 28 '22 at 14:28
  • Thank you. Just to be sure - we are talking about additional Attributes of Entity, not additional Entity (because you mentioned “record”)? Core Data of old version of the app will take only needed attributes of Entity and ignore any additional, that has new Schema? – mosariot Aug 28 '22 at 17:40
  • 1. yea I was referring to record as an attribute. 2. true – Stamenkovski Aug 28 '22 at 20:10
  • May I know, there are 2 group of users - The one who running old app and old DB schema, and the one with updated new app and new DB schema. Once, we deploy the latest DB schema to iCloud production, what will happen to the users with old app? Are they going to face app failure unless they upgrade the app? Thank you. – Cheok Yan Cheng Sep 23 '22 at 10:50