How can I disable ARC for a single file in a project?

I am using ARC successfully in my project. 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. 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

Xcode中

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


Disable ARC on MULTIPLE files:

  • Select desired files at Target/Build Phases/Compile Sources in Xcode
  • PRESS ENTER
  • Type -fno-objc-arc
  • Press Enter or Done
  • ;)

    在这里输入图像描述


    For Xcode 4.3 the easier way might be: Edit/Refactor/Convert to objective-C ARC, then check off the files you don't want to be converted. I find this way the same as using the compiler flag above.

    链接地址: http://www.djcxy.com/p/45760.html

    上一篇: 来自Swift的C代码

    下一篇: 如何禁用项目中单个文件的ARC?