ios 编译时出现ARC错误

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

ARC error when compiling

objective-ciosautomatic-ref-counting

提问by Ben

I'm trying to compile using the LLVM GCC 4.0 compiler, and I get this error in multiple of my .m files: ARC forbids explicit message send of 'release' I've tried using -fno-objc-arc as a compiler flag but that returns the error: Unrecognized command line option "-fno-objc-arc".

我正在尝试使用 LLVM GCC 4.0 编译器进行编译,并且在我的多个 .m 文件中出现此错误:ARC 禁止“发布”的显式消息发送我已尝试使用 -fno-objc-arc 作为编译器标志但这会返回错误:无法识别的命令行选项“-fno-objc-arc”。

How can I solve this?

我该如何解决这个问题?

回答by jtbandes

Simply remove all calls to -release. You're not allowed to call -releaseunder ARC because the compiler will insert all the necessary retain/releasecalls for you. Read more about ARC here.

只需删除对 的所有调用-release。你不能-release在 ARC 下调用,因为编译器会为你插入所有必要的retain/release调用。在此处阅读有关 ARC 的更多信息。

The other way is to use the conversion tool, and Xcode can convert your project to ARC (including removing these calls) for you:

另一种方法是使用转换工具,Xcode 可以为您将您的项目转换为 ARC(包括删除这些调用):

To disable ARC entirely, change your build settings:

要完全禁用 ARC,请更改构建设置:

However I'd recommend you start using ARC, it will make things a lot easier and actually faster too.

但是我建议你开始使用 ARC,它会让事情变得更容易,实际上也更快。

回答by HCdev

If you happen to be using the ASI (http://allseeing-i.com/ASIHTTPRequest/How-to-use) api, refer to this answer as it needs to be built using -fno-obj-arc flags for specific classes... Files doesn't support the ARC feature, how to deal withand refer to the answer titled 'Disable ARC for that one class'

如果您碰巧使用 ASI ( http://allseeing-i.com/ASIHTTPRequest/How-to-use) api,请参阅此答案,因为它需要使用特定类的 -fno-obj-arc 标志构建...文件不支持 ARC 功能,如何处理和参考标题为“为该一类禁用 ARC”的答案