Differences between [NSArray arrayWithArray:] and [NSArray copy]

前端 未结 7 2040
清歌不尽
清歌不尽 2021-02-12 13:50

lately I work much with arrays and I\'m wonder.. what\'s diffrences between those two lines.

NSArray *array = [NSArray arrayWithArray:someArray];
7条回答
  •  孤独总比滥情好
    2021-02-12 14:16

    One of them is probably faster. Run them a million times and see if anyone wins.

    In case of NSArray vs NSMutableArray, an immutable array being copied does not have to actually return a copy since it can't change. However, if you have a mutable array, it would need to be copied since you could change the original. And of course doing a mutable copy always needs to return a new object.

    In your entire app, the speed and memory difference is probably not going to matter compared to everything else that's going on.

提交回复
热议问题