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
Xcode ARC (automatic reference counting), "release is unavailable"
提问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 ARC
issue?
我该如何解决这个ARC
问题?
回答by Aleksander Azizi
The two options given by NJonesare valid and effective ways of dealing with ARC
incompatibility. However, you do have a third option. Disabling ARC
for specificfiles.
NJones给出的两个选项是处理ARC
不兼容问题的有效方法。但是,您确实有第三种选择。禁用ARC
对特定文件。
Giving the flags -fno-objc-arc
to your non ARC
compatible compile sources affectively marks them as such upon compilation.
-fno-objc-arc
为不ARC
兼容的编译源提供标志会在编译时有效地标记它们。
You can find your compile sources under Targets
→ Your App
→ Build Phases
→ Compile Sources
.
您可以在Targets
→ Your App
→ Build 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 retain
release
autorelease
NSAutoReleasePools
and retainCount
calls, since ARC makes them for you. With the exception of NSAutoReleasePool
s They have been replaced by @autorelease{}
.
2) 删除所有retain
release
autorelease
NSAutoReleasePools
和retainCount
调用,因为 ARC 为您制作它们。除NSAutoReleasePool
s外,它们已被 替换@autorelease{}
。
The second option has been automated by apple see this question to use the refactoring tool.
第二个选项已被苹果自动化,请参阅此问题以使用重构工具。