{"id":8657,"date":"2014-04-05T21:27:16","date_gmt":"2014-04-06T01:27:16","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=8657"},"modified":"2014-04-05T21:34:37","modified_gmt":"2014-04-06T01:34:37","slug":"adding-arc-code-to-a-project-that-also-compiles-for-i386","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2014\/04\/05\/adding-arc-code-to-a-project-that-also-compiles-for-i386\/","title":{"rendered":"Adding ARC Code to a Project That Also Compiles for i386"},"content":{"rendered":"<p><a href=\"http:\/\/lapcatsoftware.com\/articles\/winter-is-coming.html\">Jeff Johnson<\/a>:<\/p>\n<blockquote cite=\"http:\/\/lapcatsoftware.com\/articles\/winter-is-coming.html\"><p>The <code>ARCHS<\/code> build setting for your framework includes both <code>i386<\/code> and <code>x86_64<\/code>. 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 <code>#if __LP64__<\/code> to conditionally compile the code for 64-bit. As a consequence, the files will simply be empty when compiling <code>i386<\/code>. Finally, ARC can be enabled for individual files with the <code>-fobjc-arc<\/code> compiler flag. In Xcode, you can set per-file flags under Build Phases in the Compile Sources build phase. The catch, for &ldquo;fat&rdquo; or &ldquo;universal&rdquo; builds that are both 32- and 64-bit, is that you cannot set your per-file flags to <code>-fobjc-arc<\/code>. Why not? Because the per-file compiler flag applies to every architecture, but <code>-fobjc-arc<\/code> is an invalid flag for <code>i386<\/code>. So your build will die.<\/p>\n<p>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 <code>MY_FRAMEWORK_USE_ARC<\/code>. Make the build setting empty. Then create a per-architecture variant of <code>MY_FRAMEWORK_USE_ARC<\/code> for Intel 64-bit, and set that variant to <code>-fobjc-arc<\/code>. You'll now be able to use <code>$MY_FRAMEWORK_USE_ARC<\/code> as the per-file flag in your build phase, and the flag will have the appropriate definition as each architecture is built.<\/p><\/blockquote>\n<p>Also, when you&rsquo;re in Xcode&rsquo;s Compile Sources view, you can select multiple files and press Return to batch-edit the Compiler Flags.<\/p>","protected":false},"excerpt":{"rendered":"<p>Jeff Johnson: The ARCHS build setting for your framework includes both i386 and x86_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. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[55,69,54,71,226],"class_list":["post-8657","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-arc","tag-cocoa","tag-objective-c","tag-programming","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/8657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=8657"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/8657\/revisions"}],"predecessor-version":[{"id":8659,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/8657\/revisions\/8659"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=8657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=8657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=8657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}