本文介绍了NSPredicate匹配多个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经研究过过滤应用程序中的数据,并建议您查看NSPredicate.我一直在Apress的其中一本书中进行研究,但是在查找示例时遇到了问题,因此我试图创建一个示例.
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.
如果我有这样的事情:
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
推荐答案
就这么简单
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName == %@) || (lastName == %@) || (age == %i)", <name>, <lastName>, <age>];
这篇关于NSPredicate匹配多个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!