【发布时间】:2015-04-03 13:07:09
【问题描述】:
我需要的任何一种解决方案。建议我最好的答案。
我有数百个这样的数组给我最好的解决方案。我不喜欢嵌套 ForLoops
1。我需要通过 ObjectAtIndex : 0 Distinct Union the Array,并且还需要在 ObjectAtIndex : 1 中求和它们的值。
A--> [[1,"100.0"],[2,"100.0"],[2,"100.0"],[3,"100.0"],[4,"100.0"],[3 ,"100.0"],[4,"100.0"]]
B--> [[1,250],[2,250],[1,250],[3,"200.2"],[1,"200.2"],[4,"200.2"],[1,"200.2" ],[4,"200.2"]]
我需要这样的A--> [[1,"100.0"],[2,"200.0"],[3,"200.0"],[4,"200.0"]]
2。我必须在 Dictionary 中设置对象 A 和 B 数组。但如果键存在于字典中,则将该值与现有值相加。
{
A = {
1 = 100;
2 = 100;
3 = 100;
4 = 100;
};
B = {
1 = 250;
2 = 250;
3 = "200.2";
4 = "200.2";
};
}
喜欢
NSArray* uniqueValues = [data valueForKeyPath:[NSString stringWithFormat:@"@distinctUnionOfObjects.%@", @"self"]];
【问题讨论】:
标签: ios objective-c arrays nsdictionary