Possible Duplicate:
How do I create a multidimensional array?
I’m new to programming and objective C, so although I have found a few questions on here that discuss multidimensional arrays, I’m not quite getting what I need to do in order to build and use my own.
I need to make an array that has 16 rows and 3 columns. The array needs to accept string objects. I do not know how to create this, fill it, or access its contents. Would anyone be kind enough to break it down for me?
I’d suggest you use a C-array, as an
NSArraydoesn’t support multiple dimensions. You could declare the array you described like this:Setting and accessing any string of this array is quite straight-forward:
However, you could use an
NSArray(orNSMutableArray), but that would be a bit less elegant:Those three
NSMutableArrays would be the three columns of your two-dimensional array.Edit
Using an
NSArray, it might be easier to use a loop to fill it: