Re: Newbie Question: Multidimensional NSMutableArray Creation
Re: Newbie Question: Multidimensional NSMutableArray Creation
- Subject: Re: Newbie Question: Multidimensional NSMutableArray Creation
- From: Stefan Arentz <email@hidden>
- Date: Mon, 14 May 2001 12:04:04 +0200
On Mon, May 14, 2001 at 07:35:19PM +1000, William Jamieson wrote:
>
Hello All,
>
>
I am new to java and java-cocoa programming and I have been trying to figure
>
out a workaround to create a multidimensional NSMutableArray.
>
>
I have a NSTableView (with 4 columns and a variable number of rows) in a
>
window with a custom class as its DataSource. What I really want to do is
>
have an Parent NSMutableArray that is an array of Rows (also
>
NSMutableArrays). Thus creating a (workaround) multidimensional Array
>
(similar to a String[][] in java).
>
>
When I need to access cell data (eg. Row 3, Column 2) from the Array System
>
I can set a variable to the row 3 object (an NSMutableArray). I can then get
>
the 2nd object in the Row which represents the 2nd Column Data for that row.
>
>
If I need to replace a cell's data (eg. Row 3, Column 2) from the Array
>
System I can set a variable (eg. 'myExtractedRow') to the row 3 object (an
>
NSMutableArray). I can then replace the 2nd object in the Row which
>
represents the 2nd Column Data for that row. Following this can replace the
>
3rd object in the parent array with the new 'myExtractedRow' Array'.
>
>
Qusetions:
>
1 . How do I create an NSMutableArray of NSMutableArrays (if this is even
>
possible)?
I have not used Cocoa/Java, so here's a twoliner in objc. You should be
able to translate that into java...
NSMutableArray *theRows = [[NSMutableArray array] retain];
[theRows addObject: [NSMutableArray array: 3]];
This is all pretty basic stuff.
>
2. How do I set up the parent NSMutableArray and and set up the methods to
>
add and remove rows (also NSMutableArray's) from the parent array?
This is all documented in the NSArray and NSMutableArray documentation.
>
3. Is there a better/easier way to do this other than what I am proposing?
Well. It works, but is very expensive if you have many rows. Why don't you
create a simple object to store your data? That will be much faster; you can
access the right data for the request row/column much faster and you will not
have the overhead of arrays and many calls across the ObjC/Java bridge.
Stefan