Differences between [NSArray arrayWithArray:] and

2020-06-07 07:00发布

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

NSArray *array = [NSArray arrayWithArray:someArray];

and

NSArray *array = [someArray copy];

Which of it is faster? What in case we have NSMutableArray and mutableCopy?

7条回答
Luminary・发光体
2楼-- · 2020-06-07 07:32

In addition to the other answers, also note, that when someArray is nil, the first line will make array point to an empty array and the second will make it point to nil. This might be an important difference, especially in mutable arrays.

查看更多
登录 后发表回答