It can take a c array of object pointers:Jordan72 said:Here is the interesting specimen:
Code:+ (id)arrayWithObjects:(id *)objects count:(unsigned)count
The (id *)objects variable is what is confusing me. What is it? How do you have it set to several objects like it implies?
id myObjects[10];
int x = 0;
for (x = 0; x < 10; x++) {
myObjects[x] = [NSNumber numberWithInt:x];
}
NSArray *myArray = [NSArray arrayWithObjects:myObjects count:10];
Same here. Never used the 'count:' variant but have used the others loads of times.HiRez said:But in my experience, this method is rarely used (I have never actually had to use it in code). Usually I would use arrayWithArray: or arrayWithObjects: instead.
+ (id)arrayWithObjects:(id)firstObj, ...
id myObjects[10];
int x = 0;
for (x = 0; x < 10; x++) {
myObjects[x] = [NSNumber numberWithInt:x];
}
NSArray *myArray = [NSArray arrayWithObjects:myObjects count:10];
id objects = (id*)malloc(p_size * sizeof(id));
+ (id)arrayWithObjects:(id *)objects count:(unsigned)count
kainjow said:Eww, I think you're thinking too hard. Why not just use NSMutableArray?
Jordan72 said:From all that I've read in Objective-C and Cocoa texts, two main things stuck in my head with NSArray and NSMutableArray: If you only need a static array, then create a NSArray. If you need an array that is dynamic, then create a NSMutableArray. Why? It's more efficient.
Catfish_Man said:Premature optimization is the root of all evil
First make it work, then make it work right, then profile (using Shark, Sampler, etc...), *then* make it fast.
Jordan72 said:I do understand what you all are saying here, but this seems like more of a bandwagon argument, so I'll retort in fun...
So, when Unix was being developed, do you think that should have been the attitude? Because you know, the band wagon attitude seems to be leading where Microsoft and the old Macintosh OS led. Hurry, don't worry. And look where they are now. Mocking Unix. Which of course is a good and fine thing. Why? They can take leadership from the creaters that did take their time optimizing the concept to virtual perfection.