我可以在 CKQuery 中使用 recordID.recordName 吗?

问题描述 投票:0回答:3

CKQuery
文档说:谓词中使用的键名称对应于当前评估记录中的字段。键名称可能包括记录的元数据属性的名称例如“creationDate”或您添加到记录中的任何数据字段。

我还可以在

CKQuery
中使用哪些元数据?我可以使用
record.recordID.recordName
吗?如果可以,那么
key
是什么?

ios swift cloudkit ckrecord ckquery
3个回答
24
投票

是的,您可以创建一个 CKQuery 来搜索 recordID,如下所示:

var query = CKQuery(recordType: recordType, predicate: NSPredicate(format: "%K == %@", "creatorUserRecordID" ,CKReference(recordID: theSearchRecordId, action: CKReferenceAction.None)))

其中SearchRecordId是您要查找的recordID.recordName

元数据字段为 recordID、recordType、creationDate、creatorUserRecordID、modificationDate、lastModifiedUserRecordID、recordChangeTag

参见 https://developer.apple.com/library/ios/documentation/CloudKit/Reference/CKRecord_class/index.html#//apple_ref/doc/uid/TP40014044-CH1-SW14


0
投票

我喜欢:

NSPredicate *predicate= [NSPredicate predicateWithFormat:
      @"recordID = %@",[[CKRecordID alloc] initWithRecordName:theRecordNameForThisRecord]];

0
投票

虽然所有回复都设法正确回答了问题,但构建

CKQuery
谓词的更现代方法是使用
#keypath(_:)

let recordType: String // Record Type of the record you are looking for
let id: CKRecord.ID // ID of the record you are looking for

let predicate = NSPredicate(
   format: "%K == %@", #keyPath(CKRecord.recordID), id
)
let query = CKQuery(
    recordType: recordType, predicate: predicate
)
© www.soinside.com 2019 - 2024. All rights reserved.