Enable ARC for a Single Objective‑C File in a Mixed‑Mode Xcode Project
Learn how to enable ARC for a single Objective‑C file in a mixed‑mode Xcode project, verify the compiler inserts retain/release calls, and revert the change if needed.
11 Oct 2025, 03:45 UTC

Desired Outcome
Compile one Objective‑C source file with Automatic Reference Counting (ARC) while the rest of the project continues to use manual retain‑release memory management.
Prerequisites
- An Xcode project containing at least one .m file that you want to enable ARC for.
- Read/write access to the project directory.
- Xcode command‑line tools installed (for optional verification).
Procedure
- Open the project in Xcode.
- Select the target that contains the file.
- Open the Build Phases tab and expand Compile Sources.
- Locate the target file (e.g.,
MyViewController.m). Double‑click the Compiler Flags column for that row. - Enter
-fobjc-arcand press Return. This adds the flag only for the selected translation unit. - Alternatively, open Build Settings, search for Other C Flags, click the + button to add a per‑file setting, choose the file, and set the value to
-fobjc-arc. - Save the project and build (⌘B).
Expected Checks
- In the Build Settings view, the row for the file should show
-fobjc-arcunder Other C Flags; the project‑levelCLANG_ENABLE_OBJC_ARCremainsNofor manual‑retain‑release files. - To verify that the compiler inserted ARC calls, open Terminal, navigate to the project’s derived data folder, and run:
clang -fobjc-arc -S -o - MyViewController.m | grep -E 'objc_retain|objc_release|objc_autorelease'You should see lines such as call void @objc_retain indicating the compiler emitted retain/release calls.
clang --analyze MyViewController.m and confirm no retain/release mismatch warnings.Recovery Options
If the build fails or you observe unexpected behavior:
- Return to the Compile Sources list, delete the
-fobjc-arcflag for the file, or set it to an empty string. - Clean the build folder (⇧⌘K) and rebuild.
- If you suspect over‑release, enable zombies via Instruments → Zombies instrument to detect messages sent to deallocated instances.
Limitations
ARC only manages Objective‑C objects and Core Foundation types that are toll‑free bridged. For raw malloc/free or non‑bridged Core Foundation objects you must still call CFRelease or use the appropriate bridging casts (__bridge_retained, __bridge_transfer). Mixing ARC and manual code is safe only when ownership transfer annotations (__strong, __weak, __unsafe_unretained) are used correctly; otherwise you may see leaks or over‑releases.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.