xcode -fno-objc-arc 无法禁用 ARC

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

-fno-objc-arc not working to disable ARC

objective-cxcodememory-managementautomatic-ref-countingafnetworking

提问by Eric Brotto

I have tried the solution found in this postto disable ARC in AFNetworking files, but to no avail:

我已经尝试了在这篇文章中找到的解决方案来禁用 AFNetworking 文件中的 ARC,但无济于事:

enter image description here

在此处输入图片说明

Any ideas where I am failing? Obviously the simpler the answer the better. I have also read that creating static libraries may help, but this seems complicated.

我失败的任何想法?显然,答案越简单越好。我还读到创建静态库可能会有所帮助,但这似乎很复杂。

EDITS

编辑

I have tried deleting derived data andClean and Build andrestarting Xcode. No deals :(.

我尝试删除派生数据清理并构建重新启动 Xcode。没有优惠:(。

Also, there are no other projects in my workspace.

此外,我的工作区中没有其他项目。

回答by Eric Brotto

Weird thing. I tried adding the -fno-objc-arcflag to some Facebook files and the project finally built. I guess the lesson here is that when Xcode generates these types of errors, the source of the problem may be in another file. This may especially be true if Xcode is complaining about a file that you have already flagged!

奇怪的事情。我尝试将-fno-objc-arc标志添加到一些 Facebook 文件中,最终项目构建完成。我想这里的教训是,当 Xcode 生成这些类型的错误时,问题的根源可能在另一个文件中。如果 Xcode 抱怨您已标记的文件,则尤其如此!

enter image description here

在此处输入图片说明

Hopefully this will be of help to somebody :).

希望这会对某人有所帮助:)。

回答by Alpaslan Firat

Just a little additional hint:

只是一点额外的提示:

If you have multiple targets in your project check if you added the compiler flag -fno-objc-arcto all of them.

如果您的项目中有多个目标,请检查是否-fno-objc-arc向所有目标添加了编译器标志。

回答by Blago

"Convert to Objective-C ARC" is a code rewriting tool, -fno-objc-arc on the other hand is a compile time flag. It's simply irrelevant for the purpose of refactoring.

“Convert to Objective-C ARC”是一个代码重写工具,-fno-objc-arc 另一方面是一个编译时标志。它与重构的目的无关。

Before you click "Check", expend the target and deselect the files you want to keep ARC-free.

在单击“检查”之前,扩展目标并取消选择要保持无 ARC 的文件。

回答by DarkestOne

Actually the problem is simple. Make sure there is no carriage return after the -fno-objc-arcflag you have entered in the compiler flags dialog.

其实问题很简单。确保-fno-objc-arc在编译器标志对话框中输入的标志后没有回车。

回答by Ben Flynn

I managed to get into this state by a .mfile that #importeda .mfile that was not ARC compliant. The compiler complains about the included file, which may well be tagged -fno-objc-arc. I had to flag the .mthat was doing the including.

我设法将进入这个状态.m的文件,#imported一个.m是不是ARC兼容的文件。编译器抱怨包含的文件,该文件很可能被标记为-fno-objc-arc. 我不得不标记.m正在做的事情。

I discovered this by expanding the build output on the failing and looking at the raw log which showed the file that was failing to compile (different from the one in the warning).

我通过在失败时扩展构建输出并查看原始日志来发现这一点,该日志显示了无法编译的文件(与警告中的文件不同)。

I also needed to delete the derived data file.

我还需要删除派生的数据文件。

回答by Jalakoo

Had the same issue but was unable to find the offending file (as in Brotto's solution). So simply wrapped the non-arc complaint code snippets in the following #if statement block:

有同样的问题,但无法找到有问题的文件(如 Brotto 的解决方案)。因此,只需将非弧投诉代码片段包装在以下 #if 语句块中:

#if !(__has_feature(objc_arc))

//...non-arc code

#endif

回答by FreeAsInBeer

I was able to fix my issues by unchecking the non-ARC files in the Refactor -> Convert to Objective-C ARC modal. Even though the files were already being disincluded due to the 'fno-objc-arc' flag. Once I unchecked the files, Xcode started spitting out better errors that allowed me to find files that needed some fixing. After making those changes, I was good to go.

我能够通过取消选中 Refactor -> Convert to Objective-C ARC 模式中的非 ARC 文件来解决我的问题。即使由于“fno-objc-arc”标志,这些文件已经被排除。一旦我取消选中这些文件,Xcode 就开始吐出更好的错误,让我能够找到需要修复的文件。进行这些更改后,我很高兴。