Re: NSArray arrayWithObjects: count: method
Re: NSArray arrayWithObjects: count: method
- Subject: Re: NSArray arrayWithObjects: count: method
- From: Dave Sopchak <email@hidden>
- Date: Sun, 13 Apr 2003 01:14:17 -0700
Hi all,
yes, I was following Mmalcolm's advice and testing as well...
It crashed the second time I tried to access an array element, using
objectAtIndex:, when I allocated as an array of objects, C style (see
below).
It crashed right from the get-go when I set them to autorelease. If
NSArray isn't copying them, why would I set these things to
autorelease? Would not NSArray become responsible for them once I put
them in said NSArray?
On Sunday, April 13, 2003, at 12:49 AM, Sherm Pendley wrote:
MacdobModule *module[10];
for(i = 0; I <10; ++i)
module[i] = [[MacdobModule alloc] init]; // init a module
object
modules = [NSArray arrayWithObjects: module count:10]; // create
an array of 10 of them
That looks right.
Another way to do it is to avoid the C array entirely, by using an
NSMutableArray:
modules = [NSMutableArray arrayWithCapacity: 10];
for(i=0; i<10; i++)
[modules insertObject: [[MacdobModule alloc] init] atIndex: i];
sherm--
I'll be trying that shortly...here I was, trying to get all the
performance benefits of an immutable array :(
_______________________________________________
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.