Thursday, 27 October 2011

iPhone Development - Turn On Automatic Reference Counting (ARC) on a Single File in a Project

Off the back of my other post, Turn Off ARC, which instructs you how to configure Xcode to disable ARC for individual files, this post is the polar opposite; how to enable ARC for individual files.

To enable ARC for a single class, you should go to the "Project Navigator", click on your project, and then select the "Build Phases" tab. From the "Compile Sources" dropdown, find your class on which you wish to enable ARC. Note, you enable this on the .m implementation files, not the .h header files.

Notice that there are two columns here, "Name" and "Compiler Flags". Double click in the relevant "Compiler Flags" column for your desired class, and the following:


Clean and Rebuild your project to pick up these changes. Note, as far as I know, you cannot apply this to whole directories in one go, and have to apply it one file at a time.