I’m quite confused on how to add objects in multidimensional arrays.
Is initializing multidimensional arrays are the same with just a simple array?
This is my initialization.
testList = [[NSMutableArray alloc] init];
I need to do something like
testList[i][j] = item;
i tried
[[[testList objectAtIndex:i]objectAtIndex:j] addObject:item];
but it doesn’t seem to work 🙁
You are add to much C to do this. This is important to know how to NSMutableArray works and how it’s different compare to 2D arrays known from C/C++.
In mutable array you could store another arrays. For example:
Now you have array in first row in first array! This is something very like C/C++ 2D arrays.
So if you want to add some object to “0,0” you do this:
So now your second contains NSStrings and first contains second. Now you can loop this like you want.
—-EDIT:
IF you want 1,0 you simply need another instance of second NSMutableArray. For example you have this array:
So here you will be have 3 elements in second array.
You may want to implement NSCopying protocol to do this.