问题
I've looked into filtering my data in my app and I got a recommendation to look at NSPredicate. I've been looking into it in one of hte Apress books, but I'm having a problem finding an example so I'm trying to create one.
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 put then into an array.
Then I'm not sure how I would create the prediate to search
回答1:
it's as simple as
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName == %@) || (lastName == %@) || (age == %i)", <name>, <lastName>, <age>];
来源:https://stackoverflow.com/questions/8738752/nspredicate-matching-multiple-properties