1

I'm stuck in finding a proper solution for migrating the CloudKit scheme to my newest local Core Data Model. The CloudKit model won't update even when pushing new changes. I tried to update the scheme manually but it appears to be faulting and quite time consuming. Any suggestions?

EMart
  • 65
  • 4

2 Answers2

1

Have you tried one of the following after loading the persistent store?

try? container.initializeCloudKitSchema(options: .printSchema)

or

try? container.initializeCloudKitSchema(options: .dryRun)

And what exactly have you changed? If you're still in development, you could reset the environment in CloudKit Dashboard.

danmedia
  • 41
  • 2
  • Thank you for your honored answer. I added new columns and also added some relationships and parameters in already existing columns. – EMart Sep 22 '20 at 21:23
  • Also unfortunatly i can't create a mapping model. Not quite sure where that option moved or if it is already gone for good – EMart Sep 22 '20 at 21:24
  • I was already thinking of removing the NSPersistentCloudKitContainer as it doesn't support syncing to public or shared databases. Btw besides many options printed parameters, this was printed aswell indicating that the container should sync on it own i guess: – EMart Sep 22 '20 at 21:28
  • NSInferMappingModelAutomaticallyOption = 1; NSMigratePersistentStoresAutomaticallyOption = 1; NSPersistentCloudKitContainerOptionsKey = ""; NSPersistentHistoryTrackingKey = 1; NSPersistentStoreMirroringOptionsKey = { NSPersistentStoreMirroringDelegateOptionKey = ""; }; NSPersistentStoreRemoteChangeNotificationOptionKey = 1; – EMart Sep 22 '20 at 21:28
  • Your output looks just fine. As long as you only add things, a migration should not be a problem. I've already updated mine several times. – danmedia Sep 23 '20 at 19:25
0

In my case the problem was with a type of one Record:

  • in CloudKit it was initially synced as Double

  • than I've decided to change it's type to String

For a such type of errors you get a Core Data warning, but it is not so easy to spot it due to a number of such messages in console.

So I've removed this Record in iCloud dashboard (you could delete records only if they were not moved to Production) and after that my new scheme (with new Records and Relationships) was updated in a moment with a standard command:

let options = NSPersistentCloudKitContainerSchemaInitializationOptions()
try? container.initializeCloudKitSchema(options: options)
Viktor Gavrilov
  • 830
  • 1
  • 8
  • 13