NSPredicate匹配多个属性

时间:2012-01-05 06:58:13

标签: iphone nspredicate

我已经考虑过在我的应用中过滤我的数据,并且我建议您查看NSPredicate。我一直在用其中一本Apress书籍来研究它,但我遇到了一个问题,所以我正试图创建一个。

如果我有这样的事情:

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

创建一些对象然后放入数组。

然后我不确定如何创建搜索的预测

1 个答案:

答案 0 :(得分:5)

就像

一样简单

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