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 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?

18 Answers 11

up vote 2110 down vote accepted

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

55 upvote
  flag
So, the place to add this flag isn't too intuitive. But, in Xcode 4, in build phases, and compile sources, there are actually two columns. One for the file name, and another for the compile flags for that one file. This is where you enter this specific compiler flag. – casademora
3 upvote
  flag
Can you specify for a directory, i.e., for all files in a directory? What about for a Group? – ma11hew28
4 upvote
  flag
No directories. Only one single file at a time in the build settings :( – casademora
12 upvote
  flag
@casademora you cannot get enough upvotes for this piece of information. Thank you. – theTRON
2 upvote
  flag
Yes, this works but Xcode 4.2.1 still generates unsightly ARC errors on the editor window, although it eventually compiles just fine. You might want to put all your non-ARC files into a static library and link that to your main target. – adib
upvote
  flag
I did this but Xcode refactor cleans my flag and throws errors in the files. I run the refactor convert to ARC and the flag is not there anymore. Any help – Tony
1 upvote
  flag
@adib - restarting XCode after adding the compiler flag got rid of the ARC errors for me. – fishinear
25 upvote
  flag
@casademora you can select multiple files at once - but then don't doubleclick but hit RETURN. then just add the -fno-objc-arc and it will be added to all selected files. edit just saw the answer below this one :( – pkyeck
upvote
  flag
i just noticed this flag for all my source files in a project that i converted to use ARC. I never set the flag though. I came across this page when googling what that flag meant when i noticed it. but it appears the app does still use ARC. anyone know what's up? I want to remove the flag, but don't want to mess anything up. – Marty
upvote
  flag
After applying this compiler flag I was still getting errors. I had to click Product -> Clean and then I was able to rebuild my project successfully. – Mike
upvote
  flag
thanks a lot. just for people who didn't know, if you can't find the file you want in the compile source, press the "+" button to add files – SamChen
upvote
  flag
is there any method other then fno-objc-arc ? – Rajneesh071
upvote
  flag
Note on multiple flags: use spaces to separate them. – eduludi
1 upvote
  flag
Note that editing multiple files will overwrite any flags that it may already have. – Roberto
upvote
  flag
This works for me after adding complier flag I restart Xcode.and got rid of ARC. – Neha Ghetia

Disable ARC on MULTIPLE files:

  1. Select desired files at Target/Build Phases/Compile Sources in Xcode
  2. PRESS ENTER
  3. Type -fno-objc-arc
  4. Press Enter or Done

;)

enter image description here

2 upvote
  flag
Thx! Been looking for this feature a long time. Double-clicking doesnt work when selected multiple rows, but pressing enter does. So weird. – bobmoff
3 upvote
  flag
Oh wow. I'd spend all my karma to upvote this again. Thanks for sharing! – jemmons
upvote
  flag
this seems not work on Xcode 4.3.3 anymore. double click or press enter on the selected files doesn't bring up the dialog for putting in the -fno-ojbc-arc flag, anyone has a workaround for this? – tom
upvote
  flag
I had 4.3.3 and now 4.4 DP7 and it still works just fine. Try restarting Xcode, restarting machine and repair permissions. – Tibidabo

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.

Just use the -fno-objc-arc flag in Build Phases>Compile Sources

Note: if you want to disable ARC for many files, you have to:

  1. open "Build phases" -> "Compile sources"
  2. select files with "left_mouse" + "cmd" (for separated files) or + "shift" (for grouped files - select first and last)
  3. press "enter"
  4. paste -fno-objc-arc
  5. press "enter" again
  6. profit!

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

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

Add flag “-fno-objc-arc”.

Simple follow steps : App>Targets>Build Phases>Compile Sources> add flag after class “-fno-objc-arc”

The four Mandatory Step as explained in this video

    //1. Select desired files
    //2. Target/Build Phases/Compile Sources
    //3. Type -fno-objc-arc
    //4. Done
  1. Select Xcode project
  2. Go to targets
  3. Select the Build phases section
  4. Inside the build phases section select the compile sources.
  5. Select the file which you do not want to disable ARC and add -fno-objc-arc

Disable ARC for a particular file

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

Just use the -fno-objc-arc flag in Build Phases>Compile Sources infront of files to whom you dont want ARC to be apply.

GO to App -> then Targets -> Build Phases -> Compile Source

Now, Select the file in which you want to disable ARC

paste this snippet "-fno-objc-arc" After pasting press ENTER

in each file where you want to disable ARC.

4 upvote
  flag
your answer does not provide any addition to this old question. – vikingosegundo

Following Step to to enable disable ARC

Select Xcode project Go to targets Select the Build phases section Inside the build phases section select the compile sources. Select the file which you do not want to disable ARC and add -fno-objc-arc

upvote
  flag
Why gave negative marking. – annu
1 upvote
  flag
your answer does not provide any addition to this old question. – jomafer
upvote
  flag
What addition need. if you know better than provide us. – annu
upvote
  flag
I didn't downvote you. It is just this question was asked in Jul 11 '11 at 5:21. There are too many answers with the same answer that don't add any useful information...I suspect that someone downvote you for that reason... – jomafer
upvote
  flag
can you give me some brief on it. – annu

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.enter image description here

To disable ARC for individual files go to build phases under project settings then click on compile sources.

Select the .m file of the class you want to disable ARC for and set the compiler flags to -fno-objc-arc

source: Disable ARC For Individual Class

I think all the other answers are explaining how to disable MRC(Manual Reference Count) and enabling ARC(Automatic Reference Count). To Use MRC(Manual Reference Count) i.e. Disabling ARC(Automatic Reference Count) on MULTIPLE files:

  1. Select desired files at Target/Build Phases/Compile Sources in Xcode
  2. PRESS ENTER
  3. Type -fobjc-arc
  4. Press Enter or Done

Please Just follow the screenshot and enter -fno-objc-arc .

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.