Reputation: 33674
I have an app that uses core data and I am trying to generate filtered fetched results using NSPredicate. The model of my core data looks as following:
Essentially an author can have one or more quote. A tag can have many quote and vice versa and a Quote can belong to one or more pack (and hence a Pack can have one or more Quote).
So now I have been able to get all the quotes from an Author using the following:
self.fetchedResultsController = [Author MR_fetchAllGroupedBy:nil
withPredicate:[NSPredicate predicateWithFormat:@"quotes.@count != 0"]
sortedBy:AuthorKeys.name
ascending:YES
delegate:self];
What if now I wanted to say give me all a list of Authors which has quotes in pack x,y, and z. How would I modify the NSPredicate above?
Upvotes: 1
Views: 195
Reputation: 10054
I think the following should work.
NSArray *allowedPackNames = @[ @"x", @"y" ];
[NSPredicate predicateWithFormat:@"quotes.packs.packName IN %@", allowedPackNames];
Refer to the Format String Summary
Upvotes: 1