ios – CoreData + CloudKit Sync Points: Noticed Context Saves and Skipped Migrations

ios – CoreData + CloudKit Sync Points: Noticed Context Saves and Skipped Migrations


I’m utilizing CoreData with CloudKit in my iOS app, and I’ve encountered a sequence of points whereas syncing information. The logs present a number of context saves and migration skips, however there’s no clear indication of what may be fallacious. Beneath is an excerpt of the logs and the related CoreData setup code.

The logs repeatedly present the next:

CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate remoteStoreDidChange:]_block_invoke_2(3216): 
 - Ignoring distant change notification as a result of it did not change any entities tracked by persistent historical past: 
 (URL: file:///var/cell/Containers/Knowledge/Utility/62AABD0C-972D-4477-BB81-DA2F385B5B43/Library/Applicationpercent20Support/CloudDataModel.sqlite)

And several other skipped migrations like:

CoreData: debug: CoreData+CloudKit: -: 
Skipping migration for 'ANSCKRECORDMETADATA' as a result of it already has a column named 'ZNEEDSUPLOAD'

Right here is the configuration for my NSPersistentCloudKitContainer in PersistenceController.swift:

lazy var cloudContainer: NSPersistentCloudKitContainer = {
    let container = NSPersistentCloudKitContainer(title: "CloudDataModel")
    
    guard let description = container.persistentStoreDescriptions.first else {
        fatalError("Didn't retrieve retailer description")
    }
    
    description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
    description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
    
    let containerIdentifier = "iCloud.com.integralstudios.kalo"
    description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: containerIdentifier)
    
    container.loadPersistentStores { description, error in
        if let error = error {
            print("❌ Unable to load cloud persistent shops: (error)")
        }
    }
    
    container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
    container.viewContext.transactionAuthor = "integralstudios.kalo"
    container.viewContext.automaticallyMergesChangesFromParent = true
    
    do {
        attempt container.viewContext.setQueryGenerationFrom(.present)
        attempt container.initializeCloudKitSchema()
    } catch {
        print("⚠️ Didn't initialize CloudKit schema: (error)")
    }
    
    return container
}()

I additionally use this methodology to save lots of information:

func save() {
    let localContext = localContainer.viewContext
    let cloudContext = cloudContainer.viewContext
    
    if localContext.hasChanges {
        do {
            attempt localContext.save()
        } catch {
            print("Error saving native context: (error)")
        }
    }
    
    if cloudContext.hasChanges {
        do {
            attempt cloudContext.save()
        } catch {
            print("Error saving cloud context: (error)")
        }
    }
}

My very own logging is displaying the cloudkit performance working:

✅ CloudKit schema initialized efficiently
✅ Audio session configured efficiently
✅ Utilizing shared PersistenceController occasion
✅ Verified 6 meals in cloud context
✅ SharedDataManager: UserDefaults created
✅ SharedDataManager: Defaults registered
✅ SharedDataManager: Efficiently verified write entry

Additionally the icloud.developer DB viewer reveals nothing out of the bizarre.

  • NSCloudKitMirroringDelegate is observing adjustments however skipping many notifications.
  • It seems that persistent historical past adjustments usually are not being tracked as anticipated.
  • Some migrations are skipped resulting from present columns.

Any insights, ideas, or related experiences are drastically appreciated! Particularly something that helps me dissolve these error calls.

Leave a Reply

Your email address will not be published. Required fields are marked *