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

前端 未结 7 2043
清歌不尽
清歌不尽 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:06

    Which of it is faster?

    Don't worry about it. Premature optimization.

    The main difference: the first approach results in an autoreleased "copy" that you don't own and don't have to release, while you do own the object created on the second line. Both arrays will be immutable, by the way.

提交回复
热议问题