1

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?

Yann Bodson
  • 1,634
  • 1
  • 17
  • 29
user4174219
  • 427
  • 5
  • 13

1 Answers1

2

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)
Yann Bodson
  • 1,634
  • 1
  • 17
  • 29