20 C
Canberra
Saturday, January 18, 2025

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 knowledge. The logs present a number of context saves and migration skips, however there’s no clear indication of what is perhaps incorrect. Under 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/Software/62AABD0C-972D-4477-BB81-DA2F385B5B43/Library/Applicationpercent20Support/CloudDataModel.sqlite)

And a number of 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 avoid wasting knowledge:

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 exhibits nothing out of the extraordinary.

  • NSCloudKitMirroringDelegate is observing modifications however skipping many notifications.
  • It seems that persistent historical past modifications will not be being tracked as anticipated.
  • Some migrations are skipped as a consequence of present columns.

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

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles