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

查看:190
本文介绍了[NSArray arrayWithArray:]和[NSArray copy]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我使用数组工作,我很奇怪..这两行之间的差异。

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

NSArray *array = [NSArray arrayWithArray:someArray];

NSArray *array = [someArray copy];

哪个更快?如果我们有 NSMutableArray mutableCopy

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

推荐答案


哪个更快?

Which of it is faster?

不要担心。过早优化。

主要区别:第一种方法导致自动释放复制,你不拥有,不必发布,而你自己在第二行创建的对象。
这两个数组都是不可变的,顺便说一下。

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.

这篇关于[NSArray arrayWithArray:]和[NSArray copy]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆