Re: Two dimensional array
Re: Two dimensional array
- Subject: Re: Two dimensional array
- From: Glen Simmons <email@hidden>
- Date: Fri, 14 Nov 2003 11:51:41 -0600
Or, instead of using our trusty Cocoa hammer on this screw, we could
use a screwdriver. Since he's just wanting a 2D array of floats, why
bother with the complexity and overhead of objects within objects
within objects?
float foo[5][5];
foo[3][2] = 54.2345;
Seems simpler to me.
Glen
On Nov 14, 2003, at 10:37 AM, Roarke Lynch wrote:
On Nov 13, 2003, at 10:05 PM, Prachi Gauriar wrote:
NSArray *root;
root = [[NSArray alloc] initWithObjects:
[[NSArray alloc] initWithObjects:
[NSNumber numberWithDouble:1.1],
[NSNumber numberWithDouble:2.2],
[NSNumber numberWithDouble:3.3],
[NSNumber numberWithDouble:4.4],
[NSNumber numberWithDouble:5.5],
nil],
[[NSArray alloc] initWithObjects:
[NSNumber numberWithDouble:10.10],
[NSNumber numberWithDouble:9.9],
[NSNumber numberWithDouble:8.8],
[NSNumber numberWithDouble:7.7],
[NSNumber numberWithDouble:6.6],
nil],
...
nil ];
your nested arrays should be created with the convince method
[NSArray arrayWithObjects:] not alloc'ed and init'ed. Both nested
arrays have a retain count of 2 (1 for the alloc, 1 for the retain
that the root array calls when the nested array is added as a member).
I.e. use:
NSArray * root = [[NSArray alloc] initWithObjects:
[NSArray arrayWithObjects:@"One", @"Two", @"Three", ni],
[NSArray arrayWithObjects:@"Three", @"Four", @"Five", nil], nil];
But even beyond that, If you really want to have a mulidimensional
array I would suggest making your own class. You could run into a lot
of problems doing it this way, i.e. objects changing rows or columns
by adding or removing members. I would make a class that manages
additions and removals of items by marking an unused address w/ an
NSNull object.
Roarke Lynch
-------------------------------
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.