objective c - How to initialize NSMutableArray in iOS -


in app there huge number of array lists. that's why have added arrays in 1 main array list, , have initialized them using "for" loop.

i getting error inside "for" loop: "fast enumeration variables can't modified in arc default".

  nsmutablearray * mainarray = [[nsmutablearray alloc] initwithobjects:namearray, idarray, masteridnamearray, masteridarray, nil];      (nsmutablearray * array in mainarray) {         array = [[nsmutablearray alloc] init];     } 

yes, can not modify values of array in fast enumeration, i.e. for(x in array). object x becomes constant, hence through warning.

however can use for(int i=0; i<[mainarray count]; i++) loop achieve this.

but, wait: why want initialize after adding array. this:

//first create arrays have, //namearray //idarray //masteridnamearray //masteridnamearray //then add them in mainarray  nsmutablearray *namearray = [nsmutablearray array]; nsmutablearray *idarray = [nsmutablearray array]; nsmutablearray *masteridnamearray = [nsmutablearray array]; nsmutablearray *masteridnamearray = [nsmutablearray array]; nsmutablearray *mainarray = [@[namearray, idarray, masteridnamearray, masteridnamearray] mutablecopy]; 

note: renamed variable shake naming conventions in objective-c.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -