objective c - Auto increasing numbers in array -


i'm starting out xcode , need help. have array set up:

myarray = [nsmutablearray arraywithobjects: item1type1, item1type, item1type3, item1type4, item1type5, item1type6, item1type7, item1type8, item1type9, nil]; 

is possible auto-assign numbers elements in sequence? logic simple: item1type(i), item1type(i+1), item1type(i+2),...

many thanks

there many magic numbers in code, here go:

// build array of keys @[@"item_1_type_1", @"item_1_type_2", ..., @"item_1_type_9"] programmatically  const int numberofelements = 9; nsmutablearray *keys = [nsmutablearray arraywithcapacity:numberofelements]; (int = 1; <= numberofelements; i++) {     [keys addobject:[nsstring stringwithformat:@"item_1_type_%d", i]]; }  // extract chosen keys json dictionary array, matching // order of keys above.  nsdictionary *subdict = myjsondata[@"item1"]; nsarray *myarray = [subdict objectsforkeys:keys notfoundmarker:[nsnull null]]; 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

java - More than one row with the given identifier was found: 1, for class: com.model.Diagnosis -