NSArray objects have a fixed size, which cannot be changed after they are initialized. NSMutableArray objects can resize. A 10 × 10 array is sometimes implemented as an NSArray containing 10 separate NSArray objects, each of which contains ten elements. This quickly becomes cumbersome, sometimes it’s easier to return to simple C for such a task:
int tenByTen[10][10];
Or you can use this:
typedef struct { int y[10]; } TenInts; typedef struct { TenInts x[10]; } TenByTen;
Then you could do:
- (void) doSomethingWithTenByTen:(const TenByTen) myMatrix { NSLog ("%d", myMatrix.x[1].y[5]); }
And you can also return them from methods:
- (TenByTen) mangleTenByTen:(const TenByTen) input { TenByTen result = input; result.x[1].y[4] = 10000; return result; }
source share