#import <Foundation/Foundation.h>
#import "Person.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSMutableArray *array=[NSMutableArray array];
for (int i=0; i<10; i++) {
Person *person=[[Person alloc]init];
if (i<5) {
person.name=[NSString stringWithFormat:@"jack-%d",i];
}
else{
person.name=[NSString stringWithFormat:@"tom-%d",i];
}
NSNumber *a=[person age];
int s=[a intValue];
[person setAge:@(i+s)];
[array addObject:person];
[person release];
}
//判断是否满足条件
//NSArray *inArray=@[@"tom-8",@"jack-3",@"jack-2"];
//NSPredicate *predicate=[NSPredicate predicateWithFormat:@"age<25"];
//NSPredicate *predicate=[NSPredicate predicateWithFormat:@"name in %@",inArray];//名字是否在数组inArray中
//NSPredicate *predicate=[NSPredicate predicateWithFormat:@"name BEGINSWITH 't'|| name BEGINSWITH 'j'"];//是否以‘t’或者'j'开头
//NSPredicate *predicate=[NSPredicate predicateWithFormat:@"name ENDSWITH '-5'"];//是否以‘-5’结尾
NSPredicate *predicate=[NSPredicate predicateWithFormat:@"name like '*4'"];//是否以‘4’结尾
for (Person *p in array) {
BOOL ret=[predicate evaluateWithObject:p];
if (ret) {
NSLog(@"%@",p);
}
}
//对数组进行过滤
NSArray *filterArray=[array filteredArrayUsingPredicate:predicate];
NSLog(@"%@",filterArray);
}
return 0;
}
谓词
最新推荐文章于 2018-06-24 14:57:50 发布