OC Create dictionary, array

Source: Internet
Author: User

/* 4 Create a large number of dictionaries to pass in two arrays, key and obj, the number of array elements is unknown. Create a large number of dictionaries with the same number of elements as keys and an array with fewer elements in obj. The first element in key and the I element in obj form a key-value pair. All dictionaries are added to a mutable array, returning the address of the array. */+ (Nsarray *) Createdictionarieswithkeys: (Nsarray *) key ANDOBJS: (Nsarray *) obj//{//nsinteger count = 0;////Create a temporary  Array Save dictionary////nsmutablearray * array = [Nsmutablearray array];////If there is not an array must initialize dynamic array//Nsmutablearray * array =    [[Nsmutablearray alloc]init];//if ([key count] > [obj Count]) {//Count = [obj count];//}//else// {//Count = [key count];//}//for (Nsinteger i = 0; i < count; i++) {//nsmutabledictionary * di c = [Nsmutabledictionary dictionarywithobject:obj[i] forkey:key[i]];//[Array addobject:dic];//}//return [a]    Rray copy];//}{nsmutablearray * ary = [[Nsmutablearray alloc]init];    Nsinteger count = 0;    if ([key count] > [obj Count]) {count = [obj count];    } else {count = [key Count]; } for (Nsinteger i = 0; i < count; i++) {//nsmutabledictionary * dic = [nsmutabledictionary dictionarywithobject:obj[i] forkey:key[i];        Nsmutabledictionary * dic = [nsmutabledictionary dictionarywithobject:obj[i] forkey:key[i]; The method is wrong here!!!        Error! Nsmutabledictionary * dict = [nsmutabledictionary dictionarywithobject:<# (ID) #> forkey:<# (id<NSCopying        >) #>] nsmutabledictionary * dic = [nsmutabledictionary dictionarywithobject:obj[i] forkey:key[i];    [Ary Addobject:dic]; } return ary;}  {//Nsmutablearray * array = [Nsmutablearray array];//nsinteger count = 0;//if ([key count] > [obj Count])  {//Count = [obj count];//}//else//{//Count = [key count];//}//for (Nsinteger i = 0; i < count; i++) {//nsmutabledictionary * dic = [nsmutabledictionary dictionarywithobjects:obj[i] forkeys:key[i]];//[a Rray addobject:dic];//}//return [array copy];//}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

OC Create dictionary, array

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.