I've written a method to save records in a custom zone and it seems to be working as expected. One thing I'm not sure about, however, is the CKRecord.ID recordName. Right now I just use a UUID string. Is there a preferred way to assign the recordName? Current CloudKit examples are pretty scarce and it seems like a decent portion of the CK documentation is outdated. Thanks.
func saveToCloud(record: String, recordType: String, recordTypeField: String, reference: CKRecord?, referenceType: String?) {
let zoneID = CKRecordZone.ID(zoneName: Zone.test, ownerName: CKRecordZone.ID.default.ownerName)
let recordID = CKRecord.ID(recordName: UUID().uuidString, zoneID: zoneID)
let newRecord = CKRecord(recordType: recordType, recordID: recordID)
if let reference = reference, let referenceType = referenceType {
let newReference = CKRecord.Reference(record: reference, action: .none)
newRecord[referenceType] = newReference
}
newRecord[recordTypeField] = record
database.save(newRecord) { (_,error) in
if let err = error as? CKError {
print("ERROR =" , err.userInfo )
}
}
}
From my point of view its very clear in the docs of CKRecord.ID: