Reputation: 33644
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?
Upvotes: 0
Views: 2669
Reputation: 11
You can try to do this:
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"url = '%@' AND( type = %@ OR type = %@"), newsStory.url, [NSNumber numberWithInt:StoryHighlighted], [NSNumber numberWithInt:StorySavedAndHighlighted]];
Upvotes: 1
Reputation: 22582
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]];
Upvotes: 7