//合并相同model的数据
-(NSMutableArray *)distinguishArrayWithArray:(NSArray *)dataSource
{
//初始化一个空数组 用于return
NSMutableArray *array = [NSMutableArray arrayWithArray:dataSource];
NSMutableArray *dateMutablearray = [@[] mutableCopy];
for (int i = 0; i < array.count; i ++) {
PieModel *mo = array[i];
NSMutableArray *tempArray = [@[] mutableCopy];
[tempArray addObject:mo];
for (int j = i+1; j < array.count; j ++) {
PieModel *tmpmo = array[j];
if([mo.title isEqualToString:tmpmo.title]){
mo.count += tmpmo.count;
[tempArray addObject:tmpmo];
[array removeObjectAtIndex:j];
j -= 1;
}
}
[dateMutablearray addObject:tempArray];
}
returndateMutablearray;
}
网友评论