user4174219
user4174219

Reputation: 447

Saving a CKRecordID to CloudKit

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

Answers (1)

Yann Bodson
Yann Bodson

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

Related Questions