NSMutableArray arrayWithArray:vs. initWithArray: [英] NSMutableArray arrayWithArray: vs. initWithArray:

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

问题描述

这两种方式在我的应用中都没有任何明显的区别:

These both work in my app without any noticeable difference:

1)

theArray = [[NSMutableArray alloc] initWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:theData]];

2)

theArray = [NSMutableArray arrayWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:theData]];
[theArray retain];

但是,他们真的相当吗? (1)有一个alloc语句,而(2)没有。一个比另一个更好?

However, are they really equivalent? (1) has an alloc statement, whereas (2) does not. Is one preferable over the other?

推荐答案

效果是一样的。但是(2)效率较低(一个方便的方法= alloc + init + autorelease)。

The effect is the same. But (2) is less efficient (a convenient method = alloc + init + autorelease).


  1. alloc& init

  2. alloc→初始化自动释放保留

首选方法不是复制数组。

The preferred way is not to copy the array.

theArray = [[NSKeyedUnarchiver unarchiveObjectWithData:theData] retain];






很多关于iPhone操作系统开发的基本问题。 请先阅读关于这些的教程。

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

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