什么是謂詞?
謂詞是通過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");
};
新聞熱點
疑難解答