NSPredicate与AND和OR问题 [英] NSPredicate with AND and OR issues
本文介绍了NSPredicate与AND和OR问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下NSPredicate:
I have the following NSPredicate:
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"url = %@ AND type = %@ OR type = %@", newsStory.url, [NSNumber numberWithInt:StoryHighlighted], [NSNumber numberWithInt:StorySavedAndHighlighted]];
我想使用此特定网址和类型(突出显示或高亮显示)获取故事。但是上面的查询似乎不工作。
I wanted to fetch a story with this particular URL and type of (highlighted or highlightedandsaved). However the query above doesn't seem to work. What am I doing wrong?
推荐答案
只需将括号中的OR括起来,以避免混淆?
As simple as wrapping your OR in brackets to save any confusion?
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"url = %@ AND (type = %@ OR type = %@)", newsStory.url, [NSNumber numberWithInt:StoryHighlighted], [NSNumber numberWithInt:StorySavedAndHighlighted]];
这篇关于NSPredicate与AND和OR问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文