NSPredicate与OR返回错误 [英] NSPredicate with OR returning error

查看:71
本文介绍了NSPredicate与OR返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下谓词的问题:

I have a problem with the following predicate:

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

当我在查询中使用它时 CKQuery * query = [[CKQuery alloc] initWithRecordType:@Message谓词:谓词]; 我有一个错误,上面写着:'CKException',原因:'意外表达'。

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];

然后使用其中一个谓词执行查询它运行正常。我也试过使用NSCompoundPredicate,结果总是一样......有什么想法吗?

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?

推荐答案

<$ c $的文档c> CKQuery 列出了所有有效的谓词语法。奇怪的是,在Basic compound predicates下,它列出了 NOT AND && ; OR || 未列出,CloudKit查询谓词显然不支持。

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.

这篇关于NSPredicate与OR返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆