使用NSPredicate过滤包含字典的数组 [英] Filter Array with dictionaries using NSPredicate
本文介绍了使用NSPredicate过滤包含字典的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个数组,每个元素都是 NSDictionary
。
There is an Array with each element being a NSDictionary
.
NSMutableArray *mutArr = [NSMutableArray array];
for (Person *person in persons) {
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:person.name, @"name", person.email, @"email", nil];
[mutArr addObject:dict];
}
self.arr = [[NSArray alloc] initWithArray:mutArr];
如何使用姓名或者提交 arr
电子邮件包含字符串 @过滤字符串
使用 filterArrayUsingPredicate:
方法。
How to filer the arr
with name or email contains string @"filter string"
by using filterArrayUsingPredicate:
method.
提前致谢!
推荐答案
请参阅以下示例:
NSArray *array = [NSArray arrayWithObject:[NSMutableDictionary dictionaryWithObject:@"filter string" forKey:@"email"]]; // you can also do same for Name key...
NSArray *filteredarray = [array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(email == %@)", @"filter string"]];
这篇关于使用NSPredicate过滤包含字典的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文