Two Dimensional NSArrays
Two Dimensional NSArrays
- Subject: Two Dimensional NSArrays
- From: John Stringham <email@hidden>
- Date: Sat, 22 Sep 2001 16:34:04 -0400
Hi all,
I've run into a problem with a bit of code of mine that creates a
two-dimensional array of objects. The array is full of objects that are
quite simple - they're just NSObject subclasses with a few normal C
variables and a number of functions. Currently, I have the array set up
like so:
MyObject arrayOfMyObjects[10][10];
As of right now I have to go through all of the objects, allocate memory
and initialize them. Also, writing this array to file has proven to be a
bit tedious (iterating through the array and having each object pass a
data record back to be recorded to file.)
That said, my questions are as follows: If I were to use an NSArray, is
there a simple/elegant way to create a two dimensional array? With the
current documentation all I can see is that you would have to go through
each item and add an array of another 10 items to it. Also, are these
items automatically initialized and released? And finally, how would I
go about getting the -writeToFile: message to work properly with the
array (would making MyObject a subclass of NSData work?)
Much thanks,
-John Stringham