Reputation: 7484
Is there a way to setup a NSPredicate
that will search for all items in an NSArray
?
something like:
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"group.name == %@", arrayOfNames];
Upvotes: 0
Views: 80
Reputation: 14477
Yes you can use NSPredicate
with NSArray
like this
NSArray *data = [NSArray arrayWithObject:[NSMutableDictionary dictionaryWithObject:@"foo" forKey:@"BAR"]];
NSArray *filtered = [data filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(BAR == %@)", @"foo"]];
Upvotes: 0
Reputation: 539725
Use "IN" instead of "==" if the right-hand side is an array or set:
[NSPredicate predicateWithFormat: @"group.name IN %@", arrayOfNames]
Upvotes: 3