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

Błażej picture Błażej · Feb 13, 2013 · Viewed 9.2k times · Source

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?

Answer

user529758 picture user529758 · Feb 13, 2013

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.