这个方法主要是利用了数组的containsObject方法来判断数组中是否已存在改元素的特性
NSMutableArray *newArray = [NSMutableArray array];
NSMutableArray *idsArray = [NSMutableArray array];
[self.array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
Model *model = (Model *)obj;
if(![idsArray containsObject:model.id]) {
[idsArray addObject:model.id];
[newArray addObject:model];
}
}];
[self.array removeAllObjects];
[self.array addObjectsFromArray:newArray];
网友评论