ios 'release' 不可用:在自动引用计数模式下不可用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22996437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:56:28  来源:igfitidea点击:

'release' is unavailable: not available in automatic reference counting mode

iosobjective-c

提问by Dmitrii Pisarenko

I'm learning how to program on the iOS operating system using the book "Head first iPhone and iPad development" (second edition).

我正在学习如何使用“Head first iPhone and iPad development”(第二版)一书在 iOS 操作系统上进行编程。

Screenshot

截屏

When I try to compile the code from the book, I get the error that the use releasekeyword is not allowed in reference counting mode.

当我尝试编译书中的代码时,出现错误,release在引用计数模式下不允许使用 use关键字。

Do I have to explicitly release the memory in this case? If yes - how?

在这种情况下,我是否必须明确释放内存?如果是 - 如何?

回答by Ian Henry

Sounds like your book predates ARC.

听起来你的书早于ARC

You can develop an application with the same code if you disable ARC in the project settings:

如果在项目设置中禁用 ARC,则可以使用相同的代码开发应用程序:

How to disable ARC

如何禁用 ARC

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.

但是...... ARC 已经推出一段时间了,iOS 变化很快。如果这本书没有提到 ARC,这可能表明它针对的是低于 5.0 的 iOS SDK 版本,这不一定是当今学习 iOS 开发的最佳方式。

You can roughlytranslate to an ARC environment by just removing [super dealloc], retain, release, and autoreleasefrom the code you see. But it's valuable to understand whythose are there in the first place and why they're no longer necessary with ARC.

您可以通过从您看到的代码中删除, , , 和来粗略地转换为 ARC 环境。但是了解为什么首先存在这些以及为什么 ARC 不再需要它们是很有价值的。[super dealloc]retainreleaseautorelease

回答by stepik21

You have enabled Automatic Reference Counting (ARC)in your project. That means that you can skip those dealloc, releaseand autoreleasecommands. :-)

您已Automatic Reference Counting (ARC)在您的项目中启用。这意味着您可以跳过那些dealloc,releaseautorelease命令。:-)