Monday, July 8, 2024
HomeiOS Developmentios - CloudKit Sync Solely Syncs Prime-Stage Entity

ios – CloudKit Sync Solely Syncs Prime-Stage Entity


I’ve created a Core Knowledge setup with CloudKit sync. Domestically, the whole lot works nice, and I can see all my synced knowledge within the CloudKit Dashboard. Nevertheless, when I attempt to sync knowledge to a different gadget, solely the top-most entity is out there. I’ve tried opening the database on each the gadget and the simulator, but when the info is coming from iCloud, solely the top-level objects can be found, with no associated objects.

For instance, I’ve three entities: One, Two, and Three. Entity One has a relationship with Entity Two, and Entity Two has a relationship with Entity Three. After I create an occasion of Entity One with associated cases of Entities Two and Three and put it aside, I can see all information within the CloudKit Dashboard. Nevertheless, Entities Two and Three don’t sync to different units.

Right here is the code I’m utilizing:

cloudContainer = NSPersistentCloudKitContainer(identify: "Cloud")
cloudContainer.viewContext.automaticallyMergesChangesFromParent = true
cloudContainer.viewContext.identify = "CloudMain"
cloudContainer.viewContext.mergePolicy = NSMergePolicy(merge: .mergeByPropertyObjectTrumpMergePolicyType)

guard let description = cloudContainer.persistentStoreDescriptions.first else {
    fatalError("Did not initialize persistent container")
}
description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)

cloudContainer.loadPersistentStores(completionHandler: { [weak self] retailer, error in
    if let error = error as NSError? {
        fatalError("Unresolved error loading cloud retailer: (error), (error.userInfo)")
    }
    guard let self = self else { return }

    cloudBackgroundContext = cloudContainer.newBackgroundContext()
    cloudBackgroundContext?.mergePolicy = NSMergePolicy(merge: .mergeByPropertyObjectTrumpMergePolicyType)
    cloudBackgroundContext?.automaticallyMergesChangesFromParent = true
    cloudBackgroundContext?.identify = "CloudBackground"
})

do {
    strive cloudContainer.viewContext.setQueryGenerationFrom(.present)
} catch {
    fatalError("Did not pin viewContext to the present era: (error)")
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments