What about 2 dimensional NSMutableArrays?


#1

Does any have an example of using a 2 Dimensional NSMutable array, Where I could changes specific fields for BNRItems?


#2

You can easily create a second dimension by adding your arrays to another array, to a dictionary,
or by simply creating a static array from them:

//  main.m

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    @autoreleasepool {
        
        NSMutableArray *A1 = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", nil];
        NSMutableArray *A2 = [NSMutableArray arrayWithObjects:@"i", @"ii", @"iii", nil];
        NSMutableArray *A3 = [NSMutableArray arrayWithObjects:@"one", @"two", @"three", nil];

        NSMutableArray *twoDArray [] = {A1, A2, A3};
        
        const NSUInteger N = sizeof (twoDArray) / sizeof(twoDArray [0]);
        
        for (NSUInteger x = 0; x < N; ++x)
        {
            NSLog (@"%@", twoDArray [x]);
        }
    }
    return 0;
}

The output:

2012-08-22 11:50:22.150 TwoDArrays[25072:403] (
    1,
    2,
    3
)
2012-08-22 11:50:22.152 TwoDArrays[25072:403] (
    i,
    ii,
    iii
)
2012-08-22 11:50:22.152 TwoDArrays[25072:403] (
    one,
    two,
    three
)

#3

Wow, outstanding example, very simple to understand, thanks for that!