CKQuery, where does the predicate have a link, not a field?

I need to create CKQuery where the predicate contains the record link , not the record field.

Like this

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

How to set o is a CKReference, not a field!

I get this error:

Type mismatch of field value in query predicate for field 'o'

+6
source share
2 answers

I found in the CKQuery class reference an answer, or at least an example of how to use CKReference in CKQuery :

 CKReference* recordToMatch = [[CKReference alloc] initWithRecordID:employeeID action:CKReferenceActionNone]; NSPredicate* predicate = [NSPredicate predicateWithFormat:@"employee == %@", recordToMatch]; 

To match records that reference another record that you know, create a predicate that matches the field containing the reference object, as shown in Listing 1. In the example, the record employee field contains a CKReference object that points to another record. When the request is executed, a match occurs when the identifier in the locally created CKReference object is the same identifier that is specified in the specified record field.

+10
source

You can use CKRecord or CKRecordID , with or without CKReference , to match the relationship.

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) 
+10
source

Source: https://habr.com/ru/post/972848/


All Articles