Xcode ARC(自动引用计数),“发布不可用”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8236797/
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-09-09 04:10:45  来源:igfitidea点击:

Xcode ARC (automatic reference counting), "release is unavailable"

xcodecocoaautomatic-ref-counting

提问by cbbcbail

For my first time using Xcode I was following a tutorialonline. I did everything as the tutorialshowed me, but I am afraid that it's too outdated.

我第一次使用 Xcode 时,我正在学习在线教程。我按照教程向我展示的一切都做了,但我担心它太过时了。

The error I encounter is:

我遇到的错误是:

[font_attributes release]; 

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

ARC forbids explicit message send of 'release'

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

ARC 禁止“发布”的显式消息发送

My knowledge on Cocoa and Xcode is limited, but I still wish to expand my learning.

我对 Cocoa 和 Xcode 的了解有限,但我仍然希望扩展我的学习。

How may I fix the ARCissue?

我该如何解决这个ARC问题?

回答by Aleksander Azizi

The two options given by NJonesare valid and effective ways of dealing with ARCincompatibility. However, you do have a third option. Disabling ARCfor specificfiles.

NJones给出的两个选项是处理ARC不兼容问题的有效方法。但是,您确实有第三种选择。禁用ARC特定文件。

Giving the flags -fno-objc-arcto your non ARCcompatible compile sources affectively marks them as such upon compilation.

-fno-objc-arc为不ARC兼容的编译源提供标志会在编译时有效地标记它们。

You can find your compile sources under TargetsYour AppBuild PhasesCompile Sources.

您可以在TargetsYour AppBuild Phases→下找到您的编译源Compile Sources

回答by NJones

You have two options:

您有两个选择:

1) Turn off ARC for this project. This is done by setting 'Objective-C Automatic Reference Counting'to NOin the 'Build Settings' tab of your target in the project page.

1) 关闭此项目的 ARC。这是通过在项目页面中目标的“构建设置”选项卡中将“Objective-C 自动引用计数”设置NO来完成的。

2) Remove all retainreleaseautoreleaseNSAutoReleasePoolsand retainCountcalls, since ARC makes them for you. With the exception of NSAutoReleasePools They have been replaced by @autorelease{}.

2) 删除所有retainreleaseautoreleaseNSAutoReleasePoolsretainCount调用,因为 ARC 为您制作它们。除NSAutoReleasePools外,它们已被 替换@autorelease{}

The second option has been automated by apple see this question to use the refactoring tool.

第二个选项已被苹果自动化,请参阅此问题以使用重构工具