NSPredicate matching multiple properties

I studied filtering my data in my application and got a recommendation to look at NSPredicate. I studied it in one of the hte books of Apress, but I had a problem finding an example, so I'm trying to create it.

If I had something like this:

myObject : NSObject @property (nonatomic, retain) NSString *firstName; @property (nonatomic, retain) NSString *lastName; @property (nonatomic, assign) NSInteger age; 

create some objects and then put them in an array.

Then I'm not sure how to create a search query

+1
source share
1 answer

it's as simple as

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName == %@) || (lastName == %@) || (age == %i)", <name>, <lastName>, <age>];

+5
source

All Articles