什么是谓词?
谓词是通过NSPRedicate,是通过给定的逻辑条件作为约束条件,完成对数据的筛选。
NSArray *array = [[NSArrayalloc]initWithObjects:@"zhangsan",@"lisi",@"wangwu",@"xiaoliu",@"wulili",nil];
NSPredicate *preBegin= [NSPredicatepredicateWithFormat:@"SELF beginswith[c] %@",@"w"];
//通过filteredArrayUsingPredicate过滤数组
NSArray *preBeginArray = [arrayfilteredArrayUsingPredicate:preBegin];
NSPredicate *preContain = [NSPredicatepredicateWithFormat:@"SELF contains[c] %@",@"i"];
NSArray *preContainArray = [arrayfilteredArrayUsingPredicate:preContain];
NSLog(@"preBeginArray>>%@",preBeginArray);
NSLog(@"preContainArray>>%@",preContainArray);
//初始化一个查询条件
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@"SELF IN %@",@[@"bei",@"jing",@"huan",@"ying",@"ni"]];
if ([predicateevaluateWithObject:@"huan"]) {//判断数据在不在结果集中
NSLog(@"huan");
};
新闻热点
疑难解答