János
János

Reputation: 35038

Am I able to use recordID.recordName in a CKQuery?

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

Answers (3)

Witek Bobrowski
Witek Bobrowski

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

Peter B. Kramer
Peter B. Kramer

Reputation: 16553

I like:

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

Upvotes: 0

Edwin Vermeer
Edwin Vermeer

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

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

Upvotes: 24

Related Questions