Thursday 6 December 2012

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

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.
I created a sample project that has an example: https://github.com/jaminguy/NoArc
xcode

23
 
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 Jul 26 '11 at 17:58
2
 
Can you specify for a directory, i.e., for all files in a directory? What about for a Group? – MattDiPasqualeAug 9 '11 at 13:45
3
 
No directories. Only one single file at a time in the build settings :( – casademora Aug 9 '11 at 15:15
9
 
@casademora you cannot get enough upvotes for this piece of information. Thank you. – theTRON Oct 28 '11 at 0:06
3
 
@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 Apr 7 at 13:08
show 9 more comments
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
;)
share|edit|flag

2
 
Thx! Been looking for this feature a long time. Double-clicking doesnt work when selected multiple rows, but pressing enter does. So weird. – bobmoff Apr 12 at 13:31
2
 
Oh wow. I'd spend all my karma to upvote this again. Thanks for sharing! – jemmons May 4 at 0:59
 
 
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 Jul 25 at 17:43
 
 
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 Jul 29 at 7:28
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.
share|edit|flag


Just use the -fno-objc-arc flag in build phases>compile sources
share|edit|flag

No comments:

Post a Comment