Search code examples
core-datacloudkit

When to use NSPersistentCloudKitContainer.initializeCloudKitSchema?


I'm using NSPersistentCloudKitContainer to sync and share some records between users with CloudKit and CoreData. Is working relatively well after adapting the sample code to my needs from the Apple website.

However NSPersistentCloudKitContainer has method called initializeCloudKitSchema to initialize and validate the CloudKit schema. What is the best practice to use it, as it seems it doesn't have a useful role (is not used in the Apple sample docs and code and the scheme is created anyway without it)?


Solution

  • You need to initialize your Schema each time you've made changes in your Core Data model, so these changes will be synched to iCloud and you will be able to deploy Schema / Schema changes to the Production.

    After that you could comment out the lines related to initialization - there is no need to initialize the same Schema every time. Once you need to update the Schema, just comment these lines back in.