首页 > 代码库 > 添加新数组去重 MJ刷新数据时用到
添加新数组去重 MJ刷新数据时用到
// 2个数组去重方法封装, 返回新数组, 添加了不重复的新对象 - (数量变多)
- (NSMutableArray *)quChongWithOldArr:(NSMutableArray *)oldArr addNewArr:(NSArray *)newArr
{
NSMutableArray *resultArr = [NSMutableArrayarray];
for (VShowRoomObject * newRoom in newArr) {
BOOL isExit = NO;
for (VShowRoomObject * oldRoom in oldArr) {
if ([newRoom.roomidisEqual:oldRoom.roomid]) {
// 重复
isExit = YES;
}
}
if (!isExit) {
// 不重复
[resultArr addObject:newRoom];
}
}
return resultArr;
}
// 2个数组去重方法封装, 返回新数组, 移除了重复的旧对象 - (数量变少)
- (NSMutableArray *)quChongWithOldArr:(NSArray *)oldArr removeNewArr:(NSMutableArray *)newArr
{
NSMutableArray *resultArr = [NSMutableArrayarrayWithArray:oldArr];
for (VShowRoomObject * newRoom in newArr) {
BOOL isExit = NO;
for (VShowRoomObject * oldRoom in oldArr) {
if ([newRoom.roomidisEqual:oldRoom.roomid]) {
// 重复
isExit = YES;
[resultArr removeObject:oldRoom];
}
}
if (!isExit) {
// 不重复
}
}
return resultArr;
}
添加新数组去重 MJ刷新数据时用到