Hi, I recently had an issue with one of my production apps that use Core Data
and CloudKit
where data wasn't syncing between devices, after a little bit of research I found out that the schema in the private CloudKit container needed to be initialized; which I never did.
The part I'm still not 100% sure is when to run the initializeCloudKitSchema
method after the app has been released to the AppStore
. I see that Apple recommends running it when testing by using #if DEBUG
, but... do you really want to run it every time you compile in Xcode?
Here is how I understand it at this point...
- App release, call
initializeCloudKitSchema()
to match schemas between Core Data and CloudKit. - Added or deleted an
attribute
, callinitializeCloudKitSchema()
to update the CloudKit schema. - Renamed an
attribute
, callinitializeCloudKitSchema()
to update the CloudKit schema. - Etc.
If my assumption above is correct, calling the initializeCloudKitSchema()
method during development would update the schema in CloudKit
before the new app version is released in the AppStore, therefore creating an issue for existing users with previous versions of the app since they will not have the latest code but will be using the latest schema which contains the new attributes.
Can someone please share their method of handling schema updates in CloudKit after the app has been released to the AppStore?
Code:
do {
try container.initializeCloudKitSchema()
} catch {
print(error)
}