如何为项目中的单个文件禁用 ARC? [英] How can I disable ARC for a single file in a project?

查看:35
本文介绍了如何为项目中的单个文件禁用 ARC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中成功使用了 ARC.但是,我遇到了一些文件(例如,在单元测试和模拟对象中),其中 ARC 的规则现在有点脆弱.我记得听说有一种方法可以在每个文件的基础上禁用 ARC,但我一直找不到这个选项.

这可能吗?如何在每个文件的基础上禁用 ARC?

解决方案

可以通过为单个文件添加 -fno-objc-arc 编译器标志来禁用单个文件的 ARC.

您在目标 -> 构建阶段 -> 编译源中添加编译器标志.您必须双击 Compiler Flags 下行的右列.您也可以通过按住 cmd 按钮选择文件,然后按 Enter 键调出标志编辑框来将其添加到多个文件中.(请注意,编辑多个文件将覆盖它可能已有的任何标志.)

我创建了一个示例项目,其中包含一个示例:

I am using ARC successfully in my project. However, I have encountered a few files (e.g., in unit tests and mock objects) where the rules of ARC are a little more fragile right now. I recall hearing that there was a way to disable ARC on a per-file basis, though I have been unable to find this option.

Is this possible? How do I disable ARC on a per-file basis?

解决方案

It is possible to disable ARC for individual files by adding the -fno-objc-arc compiler flag for those files.

You add compiler flags in Targets -> Build Phases -> Compile Sources. You have to double click on the right column of the row under 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. (Note that editing multiple files will overwrite any flags that it may already have.)

I created a sample project that has an example: https://github.com/jaminguy/NoArc

See this answer for more info: Disable Automatic Reference Counting for Some Files

这篇关于如何为项目中的单个文件禁用 ARC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆