类方法和实例方法的疑问。。。

2013-10-12 11:00:26 +08:00
 qlqsh
比如:
NSArray *array = [[NSArray alloc] init];
NSArray *array = [NSArray array];

以前的时候是,一个需要自己释放,一个是自动释放。但现在ARC的环境下,是不是2个方法有点多余了呢。

有哪位了解,在目前ARC的情况下,2者安全上、性能上有什么差别?

苹果是不是考虑,可以放弃一个呢?这样的话,iOS的整体API能下降3成多吧?

有哪位前辈,高人指点一下?
3395 次点击
所在节点    iDev
4 条回复
fgwww
2013-10-12 11:10:23 +08:00
又不是所有的项目都上ARC了。你总得给人留条活路吧。一上来把这种最初的api都废弃掉你想让大家玩命改代码么?
qlqsh
2013-10-12 12:14:13 +08:00
这不是方向嘛。嘿嘿。。。
lldong
2013-10-12 13:46:32 +08:00
第二个这种叫做 Shortcut Constructor Method

• What is the external interface for creating a new object when a Constructor Method is too wordy?

• Represent object creation as a message to one of the arguments to the Constructor Method. Add no more than three of these Shortcut Constructor Methods per system you develop.

摘自 "Smalltalk Best Practice Patterns"
nevercry
2013-10-12 13:48:54 +08:00
没区别吧,字越少的写法越喜欢 NSArray *array = @[];

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/85307

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX