NSPredicate matching multiple properties

时光怂恿深爱的人放手 提交于 2019-12-08 08:12:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!