Use of or Operator on Cloudkit Predicate

Use of OR operator on Cloudkit predicate

Cloud Kit's CKQuery doesn't support OR in a predicate. See the documentation for CKQuery. It shows all the supported predicate operators and while AND and NOT are supported, OR is not.

One possible replacement for OR would be IN. I've only seen this where you wish to see if a single field contains one of several values. But your case is in reverse. Try the following but it may not work.

var userID = "0984093843897"
NSPredicate(format:"%@ IN { %K, %K, %K, %K } AND active = true", userID, "userID1", "userID2", "userID3", "userID4"]

Use CONTAINS or ANY in CloudKit predicate with an array of comparison

NSMutableArray * tagsReferencesArray = [[NSMutableArray alloc] init];

[tagsReferencesArray addObject:tag100_Reference];
[tagsReferencesArray addObject:tag300_Reference];
[tagsReferencesArray addObject:tag200_Reference];

predicate= [NSPredicate predicateWithFormat:@"ANY %@ in field_TagsReferenceList ", tagsReferencesArray];

CloudKit compound query (query with OR)

CKQuery supports AND and NOT, so you would imagine you could use simple boolean algebra to create a query based on the fact that NOT(NOT A AND NOT B) == A OR B. HOWEVER, the documentation specifically says:

"The NOT compound operator is not supported in the following cases:

You cannot use it to negate an AND compound predicate."

So you must query for each of the ORed predicates separately save them each as a SET and then take the intersection of the two sets to get the final result

CloudKit predicate: Search multiple reference fields with predicate of CKQuery

As @Thunk pointed out. Not possible as of today

Using NSPredicate with array for cloudKit search

Try replacing:

"Category == %@"

With:

"Category IN %@"


Related Topics



Leave a reply



Submit