Making two dimensional array on iOS.
By using NSMutableArray class, changeable two dimensional array can be made by like following.notice: I don't guarantee any issues caused by below source
- (NSMutableArray*)twoDimensionalArray:(int)width height:(int)height
{
NSMutableArray* folder=[NSMutableArray array];
for(int i=0;i<height;i++)
{
[folder addObject:[[NSMutableArray alloc] initWithCapacity:width]];
}
return folder;
}
- (void)exampleFunc
{
NSMutableArray* array=[NSMutableArray array];
array=[self twoDimensionalArray:2 height:2];
int k=1;
for(int j=0;j<2;j++)
{
for(int i=0; i<2;i++)
{
[[array objectAtIndex:j] addObject:[NSNumber numberWithInt:k]];
k++;
}
}
for(int j=0;j<2;j++)
{
for(int i=0; i<2;i++)
{
NSLog(@"val:%d",[[[array objectAtIndex:j] objectAtIndex:i] intValue]);
}
}
}