开发者

NSArray vs array

is this OK practice?

NSArray* myarray[3] = {nil,nil,nil}

...

myarray[0] = some NSArray

or is it better to stick with NSArray over a开发者_Go百科ll?

NSArray* myarray = [NSArray...] ?
...
[myarray addObject:..]


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 3x4 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.


I will go for the second one, because in my opinion, the NSArray already encapsulates some advanced technique to help you.

It depends on your needs, if you want to do something complex and need built in data structure and algorithm, I think you can go for NSArray.

I try to avoid mixing between 2 programming languages C and obj-C as much as possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜