标签:ios
saledGoodsArray数组中存储商品对象saledgoods,saledgoods有seatNo属性,将saledGoodsArray数组中saledgoods对象相同座位儿号的商品赋值给同一个人(personObject)的购买商品数组(purchasedGoodsArr)。
刚发现可以这样写,惭愧得紧!
dataArray = [[NSMutableArray alloc] init];
saledGoodsArray = [ShoppingCartDataCenter queryNoPayGoodsByFlightID:@"8815"];
NSMutableDictionary *personObjectDics = [[NSMutableDictionary alloc] init];
for (NSInteger i=0; i<saledGoodsArray.count; i++) {
SaledGoods *saledgoods = [saledGoodsArray objectAtIndex:i];
SCPersonObject * personObject = [personObjectDics objectForKey:[saledgoods seatNo]];
if (!personObject) {
personObject = [[SCPersonObject alloc] init];
[[personObject purchasedGoodsArr] addObject:saledgoods];
[personObjectDics setObject:personObject forKey:[saledgoods seatNo]];
}else {
[[personObject purchasedGoodsArr] addObject:saledgoods];
}
}
for (SCPersonObject * personObject in [personObjectDics allValues]) {
if ([personObject isKindOfClass:[SCPersonObject class]]) {
[dataArray addObject:personObject];
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:ios
原文地址:http://blog.csdn.net/leochang130731/article/details/48008651