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

这可能吗?如何基于每个文件禁用ARC?

推荐答案

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

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

xcode

有关更多信息,请参见此答案:

Objective-c相关问答推荐

应用程序终止时处理推送通知

在 Objective C 中将属性标记为已弃用

将 NSNumber 转换为 NSDecimalNumber

以原子方式写入文件与不写入文件之间的区别

块引用作为Objective-C中的实例变量

判断用户是否在连续的 UISlider 上完成滑动?

警告的含义在演示过程中!

OSStatus 错误代码 -34018

了解 performSegueWithIdentifier

判断 NSNumber 是否为 NaN

显示启动画面的时间超过默认秒数

判断 NSString 是否仅包含字母数字 + 下划线字符

遍历 NSString 中所有字符的最有效方法

Objective-c 协议前向声明

如何配置我的应用程序 - 菜单项被禁用?

使 UILabel 的文本加粗

Objective-c - CABasicAnimation 在动画后应用更改?

Block 隐式保留'self';明确提及touch以表明这是预期行为

使用 [NSDate date] 获取当前日期和时间

UITableViewCell中的文本居中对齐问题