• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSArray arrayWithObjects: count: method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
  • Follow-Ups:
    • Re: NSArray arrayWithObjects: count: method
      • From: Ben Dougall <email@hidden>
    • Re: NSArray arrayWithObjects: count: method
      • From: mmalcolm crawford <email@hidden>
References: 
 >Re: NSArray arrayWithObjects: count: method (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: NSArray arrayWithObjects: count: method
  • Next by Date: Count files in directory
  • Previous by thread: Re: NSArray arrayWithObjects: count: method
  • Next by thread: Re: NSArray arrayWithObjects: count: method
  • Index(es):
    • Date
    • Thread