How do you enable ARC project-wide in Xcode 4.2

54,461

Solution 1

"ARC is available in Xcode 4.2, currently in beta, and only when compiling with Clang (a.k.a. "Apple LLVM compiler"). The setting is called, obviously enough, "Objective-C Automatic Reference Counting". Turn it on, and off you go.

If you're working on existing code, changing this setting will produce an enormous quantity of errors. ARC not only manages memory for you, but it forbids you from trying to do it yourself. It's illegal to manually send retain/release/autorelease when using ARC. Since normal non-ARC Cocoa code is littered with this stuff, you'll get a lot of errors.

Fortunately, Xcode offers a tool to convert existing code. Select Edit -> Refactor... -> Convert to Objective-C ARC... and Xcode will guide you through converting your code. Although there may be some situations where it needs help figuring out what to do, the process should be largely automatic."

I took that from this link, helped me a lot: http://www.mikeash.com/pyblog/friday-qa-2011-09-30-automatic-reference-counting.html

Solution 2

For towpse, in Xcode 4.6 you will need to look for "CLANG_ENABLE_OBJC_ARC" and then change it to "Yes" to enable.

Share:
54,461
Alpinista
Author by

Alpinista

Flash and iPhone developer for Columbia Sportswear Co.

Updated on August 19, 2020

Comments

  • Alpinista
    Alpinista almost 4 years

    I have an iOS app that I want to convert to using ARC. I would just use the migration tool, but it errors out for me consistently during the preview phase.

    I know I can use the -fobjc-arc compiler directive on a file-by-file basis, but I want to enable ARC on the entire project, then turn off individual classes using -fno-objc-arc.

    New projects in 4.2 can use ARC by default, so there must be a switch somewhere.

    Can anyone help me to convert the project to ARC

  • PaulG
    PaulG over 9 years
    Not "largely automatic" at all on my end, I just spent about an hour or more getting rid of retains and autoreleases, what is the point of this Convert to Objective-C ARC? What does it do?
  • RyanG
    RyanG over 9 years
    Are you correct, you still need to manually remove the retains and releases.. Im not sure if it was Apples goal to force you to see what you don't need anymore or if it was too error prone for Xcode to remove them all itself.