Re: Multidimensional arrays
Re: Multidimensional arrays
- Subject: Re: Multidimensional arrays
- From: James Bucanek <email@hidden>
- Date: Sun, 19 Jun 2005 10:57:41 -0700
Julio Cesar Silva dos Santos wrote on Sunday, June 19, 2005:
>I was wondering if it is possible to create a multidimensional array
>in Objective-C the simple way it can be done in C, like this:
>
>static int table[2][10] = {{0,1,2,3,4,5,6,7,8,9},{0,2,4,6,8,1,3,5,7,9}};
>
>I ask this because NSArray are built with objects so I could create
>two arrays with the data I want and then a third array to hold the
>other two. Am I taking the right approach?
Yes, NSArrays hold objects, and NSArrays are objects. So NSArray can contain an array of NSArrays.
>Or maybe I should work
>with a dictionary with arrays inside?
This depends on entirely on how you want to address your data. If it really is a two dimentional array of objects, then both of your indexes are integer values and you'd use one to index the super-array and the other to index the sub-array:
id o = [[twoDimArray objectAtIndex:i] objectAtIndex:j];
You could just as easily have a dictionary of arrays, or an array of dictionaries, or an array of sets, or a set of dictionaries, ... How you want to address and organize your data will dictate what kind of collections you use.
--
James Bucanek <mailto:email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden