Reputation: 35038
CKQuery
doc says: Key names used in predicates correspond to fields in the currently evaluated record. Key names may include the names of the record’s metadata properties such as "creationDate” or any data fields you added to the record.
What else metadata can I use in a CKQuery
? Am I able to use record.recordID.recordName
, if yes, what is the key
for it?
Upvotes: 13
Views: 4474
Reputation: 4239
While all the replies have managed to answer the question correctly, here is a bit more modern approach to building a CKQuery
predicate would be to use the #keypath()
expression.
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
)
Upvotes: 0
Reputation: 16553
I like:
NSPredicate *predicate= [NSPredicate predicateWithFormat:
@"recordID = %@",[[CKRecordID alloc] initWithRecordName:theRecordNameForThisRecord]];
Upvotes: 0
Reputation: 13127
Yes, you could create a CKQuery for searching a recordID like this:
var query = CKQuery(recordType: recordType, predicate: NSPredicate(format: "%K == %@", "creatorUserRecordID" ,CKReference(recordID: theSearchRecordId, action: CKReferenceAction.None)))
Where theSearchRecordId is the recordID.recordName that you are looking for
Metadata fields are recordID, recordType, creationDate, creatorUserRecordID, modificationDate, lastModifiedUserRecordID, recordChangeTag
Upvotes: 24