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

查看:155
本文介绍了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天全站免登陆