// 去除数组中model重复 for (NSInteger i = 0; i < self.selectedModelArray.count; i++) { for (NSInteger j = i+1;j < self.selectedModelArray.count; j++) { AssistantModel *tempModel = self.selectedModelArray[i]; AssistantModel *model = self.selectedModelArray[j]; if ([tempModel.assistantId isEqualToString:model.assistantId]) { [self.selectedModelArray removeObject:model]; } } }
解释:
1.selectedModelArray是数据源数组;
2.两层循环判断model重复,因为数组中model地址都是不同的,只能通过model中唯一标示assistantId判断;
3.相等则移除即可.
4.循环结束,selectedModelArray数据源数组保存的是没有重复的model数据.
来源:https://www.cnblogs.com/pengsi/p/6668258.html