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
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.