Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-dimensional NSArray object

Is there a way to create two dimensional NSArray without nesting arrays in the primitive format aFloatArray[][].

Thank you.

like image 937
FatalMojo Avatar asked Apr 07 '10 23:04

FatalMojo


1 Answers

Unfortunately not. To create a multi-dimensional NSArray:

NSArray *multiArray = [NSArray arrayWithObjects:
    [NSMutableArray array],
    [NSMutableArray array],
    [NSMutableArray array],
    [NSMutableArray array], nil];

// Add a value
[[multiArray objectAtIndex:1] addObject:@"foo"];

// get the value
NSString *value = [[multiArray objectAtIndex:1] objectAtIndex:0];

However, you can use C code in Objective-C (since it is a strict superset of C), if it fits your need you could declare the array as you had suggested.

like image 128
pixel Avatar answered Sep 28 '22 03:09

pixel