How do you enable ARC project-wide in Xcode 4.2
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
"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
Select your project or target and then go to Build Settings and under the section Apple LLVM compiler 3.0 - Language you will see the option Objective-C Automatic Reference Counting.
For towpse, in Xcode 4.6 you will need to look for "CLANG_ENABLE_OBJC_ARC" and then change it to "Yes" to enable.