The Saledgoodsarray array stores the commodity object Saledgoods,saledgoods has the Seatno attribute, assigns to the same person the product of the Saledgoodsarray array saledgoods the same seat number ( Personobject) is an array of purchased goods (Purchasedgoodsarr).
Just found can write like this, ashamed to be tight!
DataArray = [[NsmutablearrayALLOC] init]; Saledgoodsarray = [Shoppingcartdatacenter querynopaygoodsbyflightid:@"8815"];nsmutabledictionary*personobjectdics = [[nsmutabledictionaryALLOC] init]; for(NsintegerI=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]; } }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS iterates over arrays of the same value elements to the same object's sub-arrays