Search code examples
iosnspredicatecloudkit

NSPredicate with OR returning error


I have a problem with the following predicate:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(creatorUserRecordID == %@) OR (toUser == %@)", userId, userId];

When I use it in query CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Message" predicate:predicate]; I have an error that says: 'CKException', reason: 'Unexpected expression'.

When I use these two seperately like this:

   NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"(creatorUserRecordID == %@)", userId];
NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"(toUser == %@)", userId];

And then performing query with one of these predicates it works fine. I also tried using NSCompoundPredicate but the result is always the same... Any ideas?


Solution

  • The documentation for CKQuery lists all of the valid predicate syntax. Oddly, under "Basic compound predicates" it lists NOT, AND, and &&. OR and || are not listed and apparently are not supported for CloudKit query predicates.