项目中会遇到2个数组中同时存在相同的元素,尤其是模型数组中,我们如何找出来呢
NSMutableArray *arrArray = [NSMutableArray array];
for (Rawmateriallist *model in self.listArray) {
if(model.isSelect){
for (Ingredientlist *test in model.ingredientList) {
[arrArray addObject:test.name];
}
}
}
NSMutableArray *listArray = [NSMutableArray array];
for (CalculateSetModel *model in self.dataArray) {
[listArray addObject:model.name];
}
NSArray *filterArr2 = [listArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF IN %@",arrArray]]; //筛选出arr2中在arr1里有的元素
NSLog(@"arr2共同的:%@",filterArr2);
// [listArray removeObjectsInArray:filterArr2];
//两个数组找到不同的数据
NSMutableArray *secIdArr = [NSMutableArray array];
for (Rawmateriallist *model in weakSelf.resetArray) {
[secIdArr addObject:@(model.ID)];
}
NSMutableArray *dataArr = [NSMutableArray array];
for (Rawmateriallist * obj in array) {
if(![secIdArr containsObject:@(obj.ID)]){
[dataArr addObject:obj];
}
}