Tuesday, October 27, 2009

C arrays of id objects!



Stackoverflow seems like a very nice site for Cocoa questions. I found this today, which helped me understand that in the middle of a function doing Cocoa stuff, you can still make a standard array of objects of type id.

id arrayObjects[arrayCount]

I never thought about that. In fact, one of my weaknesses is a failure to integrate barely remembered C++ and C stuff with Objective-C. The example also uses an instance method of NSArray that I hadn't noticed:

getObjects:range:

which, according to the class reference,
"copies the objects contained in the receiver that fall within the specified range to aBuffer… the size of the buffer must therefore be at least the length of the range multiplied by the size of an object reference."

I think the example is probably overkill since we want all of the objects. Also, is it really better to construct two arrays and then use

NSDictionary dictionaryWithObjects:forKeys:count:

or simply add objects and keys one by one. More efficient? I don't know. I also saw a reference to Google Toolbox for Mac. That should be an awesome resource. Thanks guys.