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

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

问题描述

我在项目中成功使用了ARC.但是,我遇到了一些文件(例如,在单元测试和模拟对象中),其中ARC规则现在更加脆弱.我记得曾经听说过有一种方法可以按文件禁用ARC,尽管我找不到此选项.

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.

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

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

推荐答案

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

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

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

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.)

我创建了一个带有示例的示例项目: https://github.com/jaminguy/NoArc

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天全站免登陆