数组中相同元素的合并
for (int i = 0; i < arrayTmp.count; i++)
{
SXStudentOrderInfoModel *model = arrayTmp[i];
double value = model.infoValue.doubleValue;
for (int j = i + 1; j < arrayTmp.count; j++)
{
SXStudentOrderInfoModel *nextModel = arrayTmp[j];
if ([model.infoTitle isEqualToString:nextModel.infoTitle])
{
value += nextModel.infoValue.doubleValue;
// 重新设置
model.infoValue = StringWithDoubleValue(value);
[arrayTmp replaceObjectAtIndex:i withObject:model];
[arrayTmp removeObjectAtIndex:j];
j -= 1;
}
}
}
网友评论