iOS 5 最佳实践(发布/保留?) [英] iOS 5 Best Practice (Release/retain?)

查看:20
本文介绍了iOS 5 最佳实践(发布/保留?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为初学者的 iPhone 程序员,编写适用于 iOS 5 或更旧版本的应用程序的最佳实践是什么?具体来说,我应该继续使用数据的释放/保留,还是应该忽略它?重要吗?

解决方案

这取决于您.您可以使用 ARC(自动引用计数)编写应用程序,Xcode 将编写粘合代码"以允许您启用 ARC 的应用程序在 iOS 4 上运行,无需修改.但是,某些事情将不起作用,最明显的是,您可能希望使用的许多库(有时)会引发无数错误,并且在开发人员发布与 ARC 兼容的更新之前您将无法使用它们.

<小时>

编辑:我最近发现您可以在每个文件的基础上关闭 ARC.请参阅.

As a beginning iPhone programmer, what is the best practice for writing apps to be used either with iOS 5 or older versions? Specifically, should I continue using the release/retain of data, or should I ignore that? Does it matter?

解决方案

It's up to you. You can write apps using ARC (Automatic Reference Counting), and Xcode will write "glue code" to allow your ARC enabled apps to run on iOS 4, no modifications required. However, certain things wont work, and most noticeably many libraries you might wish to use will (sometimes) throw up innumerable errors and you will be unable to use them until the developers release an update which is compatible with ARC.


Edit: I recently discovered that you can turn off ARC on a per-file basis. See pixelfreak's answer. So, my advice still stands, but now the 3rd-party libraries shouldn't need to be updated to work with ARC.

Here's what Apple says about opting out of ARC for specific files:

When you migrate a project to use ARC, the -fobjc-arc compiler flag is set as the default for all Objective-C source files. You can disable ARC for a specific class using the -fno-objc-arc compiler flag for that class. In Xcode, in the target Build Phases tab, open the Compile Sources group to reveal the source file list. Double-click the file for which you want to set the flag, enter -fno-objc-arc in the pop-up panel, then click Done.

See the full transition guide here.

这篇关于iOS 5 最佳实践(发布/保留?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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