0

我有以下 NSPredicate:

 fetchRequest.predicate = [NSPredicate predicateWithFormat:@"url = %@ AND type = %@ OR type = %@", newsStory.url, [NSNumber numberWithInt:StoryHighlighted], [NSNumber numberWithInt:StorySavedAndHighlighted]];

我想用这个特定的 URL 和类型(突出显示或突出显示并保存)获取故事。但是上面的查询似乎不起作用。我究竟做错了什么?

4

2 回答 2

7

就像将您的 OR 括在括号中以节省任何混淆一样简单?

fetchRequest.predicate = [NSPredicate predicateWithFormat:@"url = %@ AND (type = %@ OR type = %@)", newsStory.url, [NSNumber numberWithInt:StoryHighlighted], [NSNumber numberWithInt:StorySavedAndHighlighted]];
于 2012-11-27T21:48:33.973 回答
1

您可以尝试这样做:

fetchRequest.predicate = [NSPredicate predicateWithFormat:@"url = '%@' AND( type = %@ OR type = %@"), newsStory.url, [NSNumber numberWithInt:StoryHighlighted], [NSNumber numberWithInt:StorySavedAndHighlighted]];
于 2013-05-08T01:53:00.313 回答