我们以KK_Order为例,MyPerson有orderID属性。
创建模拟数据:
NSMutableArray* allArray = [NSMutableArray arrayWithCapacity:1];
for(intindex =0; index <10; index++) {
KK_Order* order = [[KK_Orderalloc]init];
order.orderID= [NSStringstringWithFormat:@"%d",index];
[allArray addObject:order];
}
NSMutableArray* subArray = [NSMutableArray arrayWithCapacity:1];
for(intindex =0; index <4; index++) {
KK_Order* order = [[KK_Orderalloc]init];
order.orderID= [NSStringstringWithFormat:@"%d",index];
[subArray addObject:order];
}
NSMutableSet *set1 = [NSMutableSetsetWithArray:allArray];
NSMutableSet *set2 = [NSMutableSetsetWithArray:subArray];
1:数组取并集
[set1 unionSet:set2];
2数组取并集
[set1 intersectSet:set2];
3.取差集
[set1 minusSet:set2];
谓词
新建一个字符串数组
NSArray* strArray = [NSArrayarrayWithObjects:@"1",@"2",@"5",nil];
取出allArray中orderID在strArray包含的对象。
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(orderID in %@)", strArray];
NSArray * result=[NSArray arrayWithArray:[allArray filteredArrayUsingPredicate: predicate]];
网友评论