简体   繁体   English

如何为特定文件关闭ARC

[英]How can one turn ARC off for specific file

I know I am supposed to add the compiler flag -fno-objc-arc to the compile sources in XCode 4 to accomplish this. 我知道我应该将编译器标志-fno-objc-arc到XCode 4中的编译源来完成此任务。 But it isn't working. 但它没有用。 Even with the added flag I am still getting errors in my KeychainItemWrapper.m file claiming I need to use __bridge for C pointers. 即使添加了标志,我仍然在我的KeychainItemWrapper.m文件中收到错误,声称我需要使用__bridge作为C指针。

我已经为编译的源添加了必需的标志...我错过了什么?

My project is ARC safe, but the Apple provided reference for interacting with the Keychain is not. 我的项目是ARC安全的,但Apple提供的与Keychain交互的参考不是。 I would like to just disable ARC for that single file. 我想为该单个文件禁用ARC。 What else am I missing here? 我还缺少什么?

I've had this happen more than once for me in 4.2 in different projects, but then I've not been able to reproduce it reliably enough for a bug report. 在不同的项目中,我已经在4.2中不止一次地发生了这种情况,但后来我无法对错误报告进行足够可靠的重现。 But I can say in my cases, a clean build cleared it up. 但我可以说,在我的情况下,一个干净的构建清理了它。

It is possible to disable ARC for individual files by adding the -fno-objc-arc compiler flag for those files. 通过为这些文件添加-fno-objc-arc编译器标志,可以为单个文件禁用ARC。

You add compiler flags in Targets -> Build Phases -> Compile Sources. 您可以在Targets - > Build Phases - > Compile Sources中添加编译器标志。 You have to double click on the right column of the row under Compiler Flags. 您必须双击Compiler Flags下行的右列。 You can also add it to multiple files by holding the cmd button to select the files and then pressing enter to bring up the flag edit box. 您还可以通过按住cmd按钮选择文件然后按Enter键以显示标志编辑框,将其添加到多个文件中。

I created a sample project that has an example: https://github.com/jaminguy/NoArc 我创建了一个示例项目,其中包含一个示例: https//github.com/jaminguy/NoArc

See this answer for more info: Disable Automatic Reference Counting for Some Files 有关详细信息,请参阅此答案:禁用某些文件的自动引用计数

单击“编辑”菜单,转到“重构”>“转换为Objective-C ARC”...单击项目名称旁边的显示三角形,然后检查要使用ARC的所有文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM