I just came across a line of code that was written by a co-worker and I’ve never seen this before in Obj-C. It looks like poor form and I want to change it, but it seemingly works (the app is working as expected) and I don’t even know what to change it to.
NSString **stringArray= new NSString *[numberOfStrings];
Is this OK? Would an NSArray of NSStrings make more sense?
EDIT: In order to properly free the array from memory, are any release calls needed? Currently, all I see is delete [] stringArray;.
EDIT 2: This seems to properly remove the array from memory:
for (int i=0; i < numberOfStrings; i++)
{
[stringArray[i] release];
}
delete [] stringArray;
He is using Objective-C++ (you should be able to verify that in the ‘file type’ on the right panel for the file in xcode4).
the
newkeyword is creates a new array of (NSString *) withnumberOfStringssize.To answer your question, an
NSArraywould very likely be more manageable, especially if there are different developers on the code. To use a C++ array there may have been performance issues but that depends on the context of that code.