[objective-c] How can I disable ARC for a single file in a project?

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?

The answer is


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


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.


  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


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.


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!

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


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


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

enter image description here


  1. select project -> targets -> build phases -> compiler sources
  2. select file -> compiler flags
  3. add -fno-objc-arc

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


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.


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


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


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

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

Examples related to objective-c

Adding a UISegmentedControl to UITableView Keep placeholder text in UITextField on input in IOS Accessing AppDelegate from framework? Warp \ bend effect on a UIView? Use NSInteger as array index Detect if the device is iPhone X Linker Command failed with exit code 1 (use -v to see invocation), Xcode 8, Swift 3 ITSAppUsesNonExemptEncryption export compliance while internal testing? How to enable back/left swipe gesture in UINavigationController after setting leftBarButtonItem? Change status bar text color to light in iOS 9 with Objective-C

Examples related to xcode

Undefined Symbols error when integrating Apptentive iOS SDK via Cocoapods Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64 iPhone is not available. Please reconnect the device Make a VStack fill the width of the screen in SwiftUI error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65 The iOS Simulator deployment targets is set to 7.0, but the range of supported deployment target version for this platform is 8.0 to 12.1 Xcode 10.2.1 Command PhaseScriptExecution failed with a nonzero exit code Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Xcode 10: A valid provisioning profile for this executable was not found Xcode 10, Command CodeSign failed with a nonzero exit code

Examples related to automatic-ref-counting

Shall we always use [unowned self] inside closure in Swift Always pass weak reference of self into block in ARC? Sending an HTTP POST request on iOS Objective-C declared @property attributes (nonatomic, copy, strong, weak) Objective-C ARC: strong vs retain and weak vs assign Should IBOutlets be strong or weak under ARC? performSelector may cause a leak because its selector is unknown How can I disable ARC for a single file in a project? Can I use Objective-C blocks as properties?

Examples related to manual-retain-release

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