I have a CKRecordID that I need to save to CloudKit as a reference. However when I try to save it, I get the following Error:
Cannot convert value of type 'CKRecordID?' to expected argument type 'CKRecordValue?'
Declaration of currentlySelectedUser:
var currentlySelectedUser: CKRecordID?
Retrieval of currentlySelectedUser in another CKQuery:
self.currentlySelectedUser = record.creatorUserRecordID
Saving of currentlySelectedUser:
myRecord.setObject(currentlySelectedUser, forKey: "toUser")
The error occurs at the 3rd line of code.
How do I save this CKRecordID as a reference in another CloudKit record?
You are trying to add a
CKRecordIDwhich is not a data type supported byCKRecord. As the error says, it doesn't conform to theCKRecordValueprotocol.Create a
CKReferenceand add it like this: