aDowla aDowla - 5 months ago 6
iOS Question

Where i can store multiple NSMutableArray in One Array?

I have five NSMutableArray each NSMutableArray holding another object array ...I want to store all five NSMutableArray in one array...How can i do this?

NSMutableArray *mA1 = [NSMutableArray array];
NSMutableArray *mA2 = [NSMutableArray array];
NSMutableArray *mA3 = [NSMutableArray array];
NSMutableArray *mA4 = [NSMutableArray array];
NSMutableArray *mA5 = [NSMutableArray array];


And after store all five NSMutableArray in one array ..how can i retrieve NSMutableArray from that array ....

Answer

Do it in a for cycle, no need to write that repeating code with 5 instantiations:

NSMurableArray *container = [NSMutableArray new];
for (int index = 0; index < 5; index++) {
     [container addObject:[NSMutableArray new]];
}

Then access them by container[2]

Comments