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

前端 未结 18 2925
星月不相逢
星月不相逢 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:03

    use -fno-objc-arc for each file in build phases

    0 讨论(0)
  • 2020-11-21 05:03
    1. select project -> targets -> build phases -> compiler sources
    2. select file -> compiler flags
    3. add -fno-objc-arc
    0 讨论(0)
  • 2020-11-21 05:04

    If you're using Unity, you don't need to change this in Xcode, you can apply a compile flag in the metadata for the specific file(s), right inside Unity. Just select them in the Project panel, and apply from the Inspector panel. This is essential if you plan on using Cloud Build.

    0 讨论(0)
  • 2020-11-21 05:08

    It is possible to disable ARC (Automatic Reference Counting) for particular file in Xcode.

    Select Target -> Build Phases -> Compile Sources -> Select File (double click) -> Add "-fno-objc-arc" to pop-up window.

    I had encountered this situation in using "Reachibility" files.

    This is shown in below figure :

    enter image description here

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-11-21 05:12

    It is very simple way to make individual file non-arc.

    Follow below steps :

    Disable ARC on individual file:

    1. Select desired files at Target/Build Phases/Compile Sources in Xcode

    2. Select .m file which you want make it NON-ARC PRESS ENTER Type -fno-objc-arc

    Non ARC file to ARC project flag : -fno-objc-arc

    ARC file to non ARC project flag : -fobjc-arc

    0 讨论(0)
提交回复
热议问题