Dynamically sized NSArray

Member
Posts: 22
Joined: 2007.07
Post: #1
Hi! This isn't exactly game related, but just a question about cocoa style using NSArray. I need to create an array with a number of objects of a single class that is determined at runtime. That number won't change throughout the run of the program, though, so I'm just using a plain NSArray. However, since NSArrays can't contain nil, what I'm doing now is mallocing a C array, initializing my NSArray with initWithObjects:count:, and then freeing the C array. Is there a more cocoa-ish way to do this or should I just forget about it and use NSMutableArray?
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #2
you can use [NSNull null] to represent nil and add that to the NSArray

"When you dream, there are no rules..."
Quote this message in a reply
Moderator
Posts: 1,552
Joined: 2003.10
Post: #3
If it were me, I'd initialize an NSMutableArray, add objects to it, then store it in an NSArray variable. This makes it semantically, though not physically, immutable.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cannot find symbol in dynamically loaded library Muskrat 4 3,825 Jan 25, 2010 01:54 PM
Last Post: Muskrat