iOS iterates over arrays of the same value elements to the same object's sub-arrays

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.