Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 505
Alpinista Avatar asked Sep 19 '11 20:09

Alpinista


People also ask

How do I know if ARC is enabled?

Check the HDMI connections on the back of your TV, soundbar, or receiver. If the HDMI port has ARC, it should be marked as such. Both your TV and the soundbar or receiver must have ARC for it to work.

Does Objective-C has ARC?

Automatic Reference Counting (ARC) is a memory management option for Objective-C provided by the Clang compiler. When compiling Objective-C code with ARC enabled, the compiler will effectively retain, release, or autorelease where appropriate to ensure the object's lifetime extends through, at least, its last use.

What is ARC in iOS?

Swift uses Automatic Reference Counting (ARC) to track and manage your app's memory usage. In most cases, this means that memory management “just works” in Swift, and you don't need to think about memory management yourself.


1 Answers

"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

like image 171
RyanG Avatar answered Sep 22 '22 22:09

RyanG