'release'不可用:在自动参考计数模式下不可用 [英] 'release' is unavailable: not available in automatic reference counting mode
问题描述
我正在学习如何使用Head first iPhone and iPad development(第二版)一书在iOS操作系统上进行编程。
I'm learning how to program on the iOS operating system using the book "Head first iPhone and iPad development" (second edition).
当我尝试编写书中的代码时,我得到错误,在引用计数模式下不允许使用 release
关键字。
When I try to compile the code from the book, I get the error that the use release
keyword is not allowed in reference counting mode.
我是否必须明确发布在这种情况下的记忆?如果是 - 如何?
Do I have to explicitly release the memory in this case? If yes - how?
推荐答案
听起来像你的书早于 ARC 。
如果在项目设置中禁用ARC,则可以使用相同的代码开发应用程序:
You can develop an application with the same code if you disable ARC in the project settings:
但是...... ARC已经出现一段时间了,而且iOS变化很快。如果这本书没有提到ARC,那么它可能是一个标志,它针对的是低于5.0的iOS SDK版本,这不一定是目前学习iOS开发的最佳方式。
But... ARC has been out for a while, and iOS changes fast. If the book doesn't mention ARC, it's a probably sign that it targets a version of the iOS SDK less than 5.0, which is not necessarily the best way to learn iOS development these days.
您只需删除 [super dealloc]
, retain 您看到的代码中的code>,
release
和 autorelease
。但是理解为什么首先出现在那里以及为什么ARC不再需要它们是有价值的。
You can roughly translate to an ARC environment by just removing [super dealloc]
, retain
, release
, and autorelease
from the code you see. But it's valuable to understand why those are there in the first place and why they're no longer necessary with ARC.
这篇关于'release'不可用:在自动参考计数模式下不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!