Adding ARC Code to a Project That Also Compiles for i386
The
ARCHSbuild setting for your framework includes bothi386andx86_64. The first thing you'll want to do is to put your ARC code in files that aren't used by your 32-bit apps. Next, you'll want to wrap your ARC code files with#if __LP64__to conditionally compile the code for 64-bit. As a consequence, the files will simply be empty when compilingi386. Finally, ARC can be enabled for individual files with the-fobjc-arccompiler flag. In Xcode, you can set per-file flags under Build Phases in the Compile Sources build phase. The catch, for “fat” or “universal” builds that are both 32- and 64-bit, is that you cannot set your per-file flags to-fobjc-arc. Why not? Because the per-file compiler flag applies to every architecture, but-fobjc-arcis an invalid flag fori386. So your build will die.The trick to enabling ARC for specific files in your framework is to use a per-architecture build setting. Create a User-Defined build setting, something like
MY_FRAMEWORK_USE_ARC. Make the build setting empty. Then create a per-architecture variant ofMY_FRAMEWORK_USE_ARCfor Intel 64-bit, and set that variant to-fobjc-arc. You'll now be able to use$MY_FRAMEWORK_USE_ARCas the per-file flag in your build phase, and the flag will have the appropriate definition as each architecture is built.
Also, when you’re in Xcode’s Compile Sources view, you can select multiple files and press Return to batch-edit the Compiler Flags.