is this OK practice?
NSArray* myarray[3] = {nil,nil,nil}
...
myarray[0] = some NSArray
or is it better to stick with NSArray over all?
NSArray* myarray = [NSArray...] ?
...
[myarray addObject:..]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Depends on your needs. Either way works, but I generally find that mixing Objective-C objects and C structures leads to madness as you have to maintain sanity over two different memory models; retain/release and malloc/free.
I also generally avoid multi-dimensional arrays entirely. For example, a 3×4 array of arrays can be represented as a single array of 12 items. An item at 2,3 is really at (2 + (3*width)).
Note that NSArrays can’t have “holes”. You can represent the holes, if needed, with NSNull objects. Or create a subclass of NS[Mutable]Array that allows holes.