views:

1375

answers:

3

Ok, I have some C# code that looks like this and I was wondering what other developers would recommend if I am trying to put this into Objective-C.

List<List<string>> meta_data

I'm planning on using NSMutableArray but how to exactly get that two-dimensional array figured out is my problem, since there is no such thing as a multidimensional array in Objective-C. I'm new to using NSMutableArray, so I still need some help every now and then.

I know I will just add string objects to the array using NSString once I have the whole "two-dimensional" part figured out.

A: 

You would use a NSMutableArray of NSMutableArrays containing NSStrings

Zydeco
Well I thought about that, but like you said in your comment, (you used the plural form NSMutableArrays)...how am I supposed code it so I can have an arbitrary amount of mutable arrays? The decision as to how many mutable arrays would be needed would be decided at runtime.
Josh Bradley
+4  A: 

An array can hold any object. I'm not familiar with C# code, but I imagine all your trying to do is nested arrays.

What you need to be using is objectAtIndex: for NSArrays.

NSString *hello = @"Hello World";
NSMutableArray *insideArray = [[NSMutableArray alloc] initWithObjects:hello,nil];
NSMutableArray *outsideArray = [[NSMutableArray alloc] init];
[outsideArray addObject:insideArray];
// Then access it by:
NSString *retrieveString = [[outsideArray objectAtIndex:0] objectAtIndex:0];

I think your looking for something like that. Does that help?

RyanJM
+3  A: 

Something like this:

//Create the array of strings
NSMutableArray *strings = [[NSMutableArray alloc] init];
[strings addObject:@"someString"];
[strings addObject:@"someOtherString"];

//Create the array to hold the string array
NSMutableArray *container = [[NSMutableArray alloc] init];
[container addObject:strings];
Perspx