Is there a way to create two dimensional NSArray without nesting arrays in the primitive format aFloatArray[][].
Thank you.
Is there a way to create two dimensional NSArray without nesting arrays in the primitive format aFloatArray[][].
Thank you.
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.
multiArray. To fix, use [NSMutableArray array] instead.[NSMutableArray new] to an array, its retain-count becomes 2. When the parent array is released, each of its children still has a retain-count of 1.You can do this:
NSArray *array = @[@[@"0:0", @"0:1"],
@[@"1:0", @"1:1"]];
NSString *value = array[1][0];
i think this is much shorter than "objectAtIndex" stuff.
but beware you have use Apple LLVM Compiler version >= 4.0
To insert an object in Multidimensional array in Collection or TableView cellForRowAtIndexPath:
NSString *sectionRow = [NSString stringWithFormat:@"%d:%d", indexPath.section, indexPath.row];
[dictionary setValue:[UIImage imageWithData:imageData] forKey:sectionRow];
To retrieve an object from Multidimensional array in Collection or TableView cellForRowAtIndexPath:
NSString *sectionRow = [NSString stringWithFormat:@"%d:%d", indexPath.section, indexPath.row];
UIImage *cellImage = [dictionary valueForKey:sectionRow];