Making Legacy Code Sail on ARC

So, you’re all hyped up to play with the newest iOS5 goodness, you fire up Xcode, create a new project, throw in some of you favorite 3rd party utilities from GitHub and hit build and…. boom! you see  a bunch of these:

OACall.m:75:9: error: ‘retain’ is unavailable: not available in automatic reference counting mode 

What to do?  If the code is yours, you can just run it throught the ARC conversion process and eventually you’ll be good.

But what do you do if the code you’re trying to compile is part of a 3rd party module that’s say, part of a GitHub project?  You could run it through the converter and send a pull request to the maintainer.. but that might not be how the maintainer wants to proceed, and of course if there are corrections and updates upstream, you’ll have one heck of a merge problem in your project.

Fortunately, ARC can be enabled or disabled on a file by file basis from inside Xcode.  To disable ARC, go into the project summary screen and click on the build phases; then click on the “compile sources” disclosure triangle to show all your source files.

To disable ARC, double-click on each file you wish to apply and add the foollowing compiler directive

-fno-objc-arc

After setting the compiler flag your source list will look like this:

and then click on the close box.  Unfortunately there doesn’t seem to be a way to appy this en-mass if you have a lot of non-ARC code.   Once you set this flag your code should compile normally and you’ll be good to go.

Alternatively, if the code you are including can itself be compiled into a .a file, you could just pre-compile that code and then include it as a regular static library which gets around the need for special compiler directives all together.

GD Star Rating
loading...
Twitter Digg Delicious Stumbleupon Technorati Facebook Email

About David Spector

He’s written for C|Net’s Tech Republic, InformationWeek, Fortune, WIRED and various other publications both online and in traditional print media.David HM Spector is a software developer, writer, and entrepreneur specializing in MacOSX/iOS development, and social network applications. His consulting company is Zeitgeist Information Systems, canonically known as “Zeitgeist.” (And, no, he's got nothing to do with The Zeitgeist Movie...)Connect with me on LinkedIn
Performance Optimization WordPress Plugins by W3 EDGE