NSPredicate with OR returning error

北城余情 提交于 2019-12-20 03:33:21

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/30948376/nspredicate-with-or-returning-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!