我目前正在为iPad开发一款应用程序.iOS 4.2的开发已经开始,iOS 4.3的开发正在继续(我认为将会完成).

  1. 如果我决定升级到iOS 5,是否需要从代码中删除所有[myObject retain][myObject release]条语句?

  2. 如果我使用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

Objective-c相关问答推荐

如何在 NSImage CIFilter ObjC 周围创建边框

iOS中的非延迟图像加载

使用正则表达式搜索 NSString

在我的 UIImageView 的子类中没有调用 drawRect

在 Interface Builder 中设计 UITableView 的section header

我怎样才能拥有一个同时包含图像和文本的 UIBarButtonItem?

如何在 iOS SDK 中使用语音识别?

lldb 无法打印变量值并显示错误:对 'id' 的引用不明确

将子视图添加到 UIButton

Select 时如何更改 UITableViewCell 的 colored颜色 ?

添加自定义 initWith?

了解 performSegueWithIdentifier

如何在 NSSet 或 NSArray 中搜索具有特定属性的特定值的对象?

带有 NSBlockOperation 和队列的 NSURLSession

NSHTTPCookieStorage 状态未在应用退出时保存.那里有任何明确的知识/文档吗?

使用 CocoaPods 时如何向 Xcode 添加自定义项目配置?

在 DEBUG 模式下启用和禁用 NSLog

为什么我们不能在当前队列上使用 dispatch_sync?

将 NSDate 舍入到最接近的 5 分钟

带有 UIImage 的 UIBarButtonItem 始终着色 iOS 7