1

我有一个CKRecordID需要保存到 CloudKit 作为参考。但是,当我尝试保存它时,出现以下错误:

无法转换“CKRecordID”类型的值?到预期的参数类型“CKRecordValue?”

currentSelectedUser 的声明:

var currentlySelectedUser: CKRecordID?

在另一个 CKQuery 中检索 currentSelectedUser:

self.currentlySelectedUser = record.creatorUserRecordID

currentSelectedUser 的保存:

myRecord.setObject(currentlySelectedUser, forKey: "toUser")

错误发生在代码的第 3 行。

如何将其保存CKRecordID为另一个 CloudKit 记录中的参考?

4

1 回答 1

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)
于 2016-07-27T08:16:04.690 回答