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

前端 未结 18 2866
星月不相逢
星月不相逢 2020-11-21 04:31

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 ri

18条回答
  •  执笔经年
    2020-11-21 05:09

    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

提交回复
热议问题