Reputation: 447
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?
Upvotes: 1
Views: 555
Reputation: 1654
You are trying to add a CKRecordID
which is not a data type supported by CKRecord
. As the error says, it doesn't conform to the CKRecordValue
protocol.
Create a CKReference
and add it like this:
myRecord["toUser"] = CKReference(recordID: currentlySelectedUser!, action: .None)
Upvotes: 2