Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
735 views
in Technique[技术] by (71.8m points)

objective-c - 如何为项目中的单个文件禁用ARC?(How can I disable ARC for a single file in a project?)

I am using ARC successfully in my project.

(我在项目中成功使用了ARC。)

However, I have encountered a few files (eg, in unit tests and mock objects) where the rules of ARC are a little more fragile right now.

(但是,我遇到了一些文件(例如,在单元测试和模拟对象中),其中ARC规则现在更加脆弱。)

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?

(如何按文件禁用ARC?)

  ask by casademora translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

(您可以在目标->构建阶段->编译源中添加编译器标志。)

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.

(您还可以通过以下方式将其添加到多个文件中:按住cmd按钮选择文件,然后按Enter弹出标记编辑框。)

(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

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

代码

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

(有关更多信息,请参见此答案: 禁用某些文件的自动引用计数)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...