/* 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