Reputation: 69647
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?
Upvotes: 1371
Views: 342040
Reputation: 35
Upvotes: -1
Reputation: 6631
Please Just follow the screenshot and enter -fno-objc-arc .
Upvotes: 9
Reputation: 456
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:
Upvotes: 7
Reputation: 25930
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
See this answer for more info: Disable Automatic Reference Counting for Some Files
Upvotes: 2183
Reputation: 1806
It is very simple way to make individual file non-arc.
Follow below steps :
Disable ARC on individual file:
Select desired files at Target/Build Phases/Compile Sources in Xcode
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
Upvotes: 38
Reputation: 289
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.
Upvotes: 8
Reputation: 21571
Disable ARC on MULTIPLE files:
;)
Upvotes: 464
Reputation: 137
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
Upvotes: -2
Reputation: 404
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.
Upvotes: -1
Reputation: 133
Just use the -fno-objc-arc flag in Build Phases>Compile Sources infront of files to whom you dont want ARC to be apply.
Upvotes: 2
Reputation: 36447
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 :
Upvotes: 14
Reputation: 808
Just use the -fno-objc-arc
flag in Build Phases
>Compile Sources
Upvotes: 22
Reputation: 305
Upvotes: 14
Reputation: 191
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
Upvotes: 12
Reputation: 508
Add flag “-fno-objc-arc”.
Simple follow steps : App>Targets>Build Phases>Compile Sources> add flag after class “-fno-objc-arc”
Upvotes: 6
Reputation: 752
Note: if you want to disable ARC for many files, you have to:
-fno-objc-arc
Upvotes: 36
Reputation: 985
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.
Upvotes: 45