NSArray *arr = @[@"beijing",@"shanghai",@"shenzhen",@"guangzhou",@"hangzhou"];
NSString *str = @"hang";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF CONTAINS %@",str];
NSLog(@"new arr: %@",[arr filteredArrayUsingPredicate:pred]);
Cocoa框架中的NSPredicate用于查询,原理、用法类似于SQL中的where,作用相当于数据库的过滤
时间: 2024-10-18 15:22:45