我目前正在为iPad开发一款应用程序.iOS 4.2的开发已经开始,iOS 4.3的开发正在继续(我认为将会完成).
如果我决定升级到iOS 5,是否需要从代码中删除所有
[myObject retain]
和[myObject release]
条语句?如果我使用ARC为iOS 5开发一个新应用程序,我是否需要执行某种"复古兼容性"判断?i、 e:我需要判断iOS的版本并相应地调用retain和release吗?那么,基本上,ARC是适用于所有iOS版本还是仅适用于iOS 5?
我目前正在为iPad开发一款应用程序.iOS 4.2的开发已经开始,iOS 4.3的开发正在继续(我认为将会完成).
如果我决定升级到iOS 5,是否需要从代码中删除所有[myObject retain]
和[myObject release]
条语句?
如果我使用ARC为iOS 5开发一个新应用程序,我是否需要执行某种"复古兼容性"判断?i、 e:我需要判断iOS的版本并相应地调用retain和release吗?那么,基本上,ARC是适用于所有iOS版本还是仅适用于iOS 5?
If I decide to upgrade to iOS 5, do I need to remove all [myObject retain] and [myObject release] statements from my code?
Yes, but XCode 4.2 includes a new "Migrate to Objective-C ARC" tool (in the Edit->Refactor menu), which does that for you. Calling dealloc is a different story. As mentioned in the comments the clang reference states that you should keep your the dealloc method:
Rationale: even though ARC destroys instance variables automatically, there are still legitimate reasons to write a dealloc method, such as freeing non-retainable resources. Failing to call [super dealloc] in such a method is nearly always a bug.
使用新的-fobjc ARC启用ARC
-
If I develop a new app for iOS 5 using ARC, will I need to implement some sort of "retro-compatibility" checks? I.e.: will I need to check the version of iOS and call retain and release accordingly? So, basically, is ARC available for all iOS versions or just for iOS 5?
不,因为ARC在编译时而不是运行时发挥了神奇的作用.
而不是你必须记住什么时候
关于ARC的更多信息:http://clang.llvm.org/docs/AutomaticReferenceCounting.html