首页 > 代码库 > NSPredicate
NSPredicate
1 字符串中查出保函某个字节
NSArray *array =@[@"123",@"234" , @"345"];
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@"SELF contains [cd] %@","2"];
NSArray *filterdArray = [array filteredArrayUsingPredicate:predicate];
NSLog(@"%@", filterdArray );
2.查找封装model对象的数组,根据model的一个属性NSPredicate *predicate = [NSPredicatepredicateWithFormat:@"name == %@","Ansel"];
NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate];}
3.查询数组中字典莫一个Key的值NSArray *array =@[ @{ @"lastName" : @"Turner" },
@{@"firstName" : @"Ben",@"lastName" : @"Ballard",
@"birthday":@"1972-03-24 10:45:32 +0600" }
];
NSPredicate *predicate =
[NSPredicatepredicateWithFormat:@"firstName like %@",@"firstName"];
NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate];
NSPredicate