0

I am toying with CloudKit, saving records and assets (using the private database). Managed to successfully save an CKAsset, it ends up in the _defaultZone. My Core Data Objects however somehow end up in the zone called com.apple.coredata.cloudkit.zone. I haven’t done anything explicitly with zones anywhere, how do I make both use the same (preferably _defaultZone) zone?

I think this is needed, because I give the asset an reference to the Game entity it belongs to, thinking this would enable cascaded delete (Game gets deleted, so do all assets for that game). Game is my Core Data entity

    // Game (reference record)
    let gameName = game.objectID.uriRepresentation().absoluteString
    let gameID = CKRecord.ID(recordName: gameName)

    // Create a CKRecord for the Game Image, referencing the Game
    let iconImageRecord = CKRecord(recordType: "GameIconImages")
    iconImageRecord["oid"] = gameName
    iconImageRecord["gid"] = id.uuidString
    iconImageRecord["game"] = CKRecord.Reference(recordID: gameID, action: .deleteSelf)

The extra id's are for testing/checking. I checked in the CloudKit dashboard and the reference id is correct (equal to coredata objectid), but when I click it, I get 'record not found'. My guess this is because the CKRecord and the CoreData records are in two different zones...?

Any help really appreciated, banging my head over it way too long...

DeveloperSammy
  • 167
  • 1
  • 11
  • On your device / simulator, sign into iCloud with your Apple Developer account (not personal iCloud account), now on the cloud kit dashboard you will have access to the private database records. So you can debug better. – user1046037 Aug 02 '22 at 16:44
  • I am doing that, and like I stated the dashboard says record not found when the reference link is clearly correct ... – DeveloperSammy Aug 03 '22 at 08:21
  • Now in CloudKit dashboard, there is an option to "Act as iCloud account", then choose the Recods (sidebar) and then record type and record zone from down. Select each record zone and query, if you are unable to query you might need to add recordnmae to make it queryable. – user1046037 Aug 11 '22 at 15:23
  • Yes, I know, and I am using the Dashboard intensively. Thank you! – DeveloperSammy Aug 17 '22 at 13:40
  • 1
    If you use `NSPersistentCloudKitContainer` it automatically syncs your core data objects to cloudkit and saves them in `com.apple.coredata.cloudkit.zone`. I don't think that can be changed. This record zone is managed by `NSPersistentCloudKitContainer` – user1046037 Aug 17 '22 at 17:13
  • Thanks. I now know the zones are of no further importance. – DeveloperSammy Aug 20 '22 at 13:39
  • 1
    It is still important to understand how zones work, NSPersistentCloudKitContainer is built on top of CloudKit (using CloudKit APIs internally) and so it is important to understand the concepts of CloudKit. If there is any sync errors it would help to know what causes the issue and how to fix them. Record zones are still used inside `NSPersistentCloudKitContainer` to sync records and to share records (they use zone sharing). Please go through all cloudkit WWDC videos would help a lot – user1046037 Aug 20 '22 at 16:47

0 Answers0