I am using the following code to create a CKRecord in a custom private CKRecordZone:

let noteZoneID = CKRecordZone.ID(zoneName: CloudKitManager.noteZoneName,
                                 ownerName: CKCurrentUserDefaultName)
return CKRecord(recordType: Note.recordType, zoneID: noteZoneID)

This seems to work just fine, but I am getting a warning: 'init(recordType:zoneID:)' is deprecated: Use init(recordType:recordID:) + CKRecord.ID(zoneID:) instead

If I used those methods instead, I think I would have to do something like:

let noteZoneID = CKRecordZone.ID(zoneName: CloudKitManager.noteZoneName,
                                 ownerName: CKCurrentUserDefaultName)
let recordID = CKRecord.ID(recordName: "UniqueRecordName", zoneID: noteZoneID)
return CKRecord(recordType: Note.recordType, recordID: recordID)

My problem with this method is that suddenly I am responsible for creating a unique recordName, and I don't understand why that is the case. Is there an alternate way of creating a record that removes that responsibility? Is there a specific reason why my app code should come up with the recordName?

1 Answers

0
Brian Hamm On

There's no way to bypass this for a custom zone. If you don't want to assign a recordName value, you can pass it a UUID().uuidString.

Record ID objects are normally created automatically when you create a new record, but [...] you must create record ID objects when you want to save a record in a zone other than the default zone.

https://developer.apple.com/documentation/cloudkit/ckrecord/id