2015-06-19 54 views
2

我有以下謂詞的一個問題:NSPredicate使用或返回錯誤

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

當我用它查詢CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Message" predicate:predicate];我有一個錯誤,指出:「CKException」,理由是:「意外的表情」。

當我使用這兩個seperately這樣的:

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

然後用這些謂詞能正常工作的一個進行查詢。我也嘗試使用NSCompoundPredicate,但結果總是相同的...任何想法?

回答

3

CKQuery的文檔列出了所有有效的謂詞語法。奇怪的是,在「基本複合謂詞」下,它列出了NOT,AND&&OR||未列出,顯然不支持CloudKit查詢謂詞。

+0

我在文檔中發現的是:基本化合物謂詞 AND,&& 邏輯AND。 OR,|| 邏輯或。 不,! 邏輯NOT。我錯了嗎? – Wojtek

+0

好吧。雖然NSPredicate可以使用,但CKQuery不允許使用OR進行謂詞。我的錯。你能否提示我如何用OR查詢CloudKit? – Wojtek