Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKQuery where predicate has reference and not field?

I need to create a CKQuery where the predicate contains a reference of a record, and not a field of the record.

Like this

let query = CKQuery(recordType: "OUP", predicate: NSPredicate(format: "o = %@", "FF4FB4A9-271A-4AF4-B02C-722ABF25BF44")

How do I set o is a CKReference, not field!

I get this error:

Field value type mismatch in query predicate for field 'o'

like image 622
János Avatar asked Jul 25 '14 17:07

János


1 Answers

You can use a CKRecord or CKRecordID, with or without a CKReference, to match relationships.

CKRecord:

let predicate = NSPredicate(format: "artist == %@", artist)

CKRecordID:

let predicate = NSPredicate(format: "artist == %@", artistID)

CKReference with CKRecord:

let recordToMatch = CKReference(record: artist, action: CKReferenceAction.None)
let predicate = NSPredicate(format: "artist == %@", recordToMatch)

CKReference with CKRecordID:

let recordToMatch = CKReference(recordID: artistID, action: CKReferenceAction.None)
let predicate = NSPredicate(format: "artist == %@", recordToMatch)
like image 131
Senseful Avatar answered Sep 20 '22 15:09

Senseful