iOS7下,使用@import代替#import

在xcode 5 下,為了更易于開發(fā),增加了modules和 auto-linking這兩個(gè)新特性。用@import來增加框架到項(xiàng)目中,比用 #import會(huì)更有效. 我們來看看為什么:

"Modules for system frameworks speed build time and provide an alternate means to import APIs from the SDK instead of using the C preprocessor. Modules provide many of the build-time improvements of precompiled headers with less maintenance or need for optimization. They are designed for easy adoption with little or no source changes. Beyond build-time improvements, modules provide a cleaner API model that enables many great features in the tools, such as Auto Linking."

Modules and auto-linking 默認(rèn)情況下是enabled的。 如果是舊的項(xiàng)目,你可以通過設(shè)置"Language - Modules." 來設(shè)置Enable Modules 和Link Frameworks Automatically 為Yes。


另外一個(gè)使用moudules的好處是你再也不用去鏈接你的framework到你的項(xiàng)目了。例如,在以前,如果你要使用MapKit這個(gè)框架,你要這樣做

  1. 使用語句 #import <MapKit/MapKit.h> 導(dǎo)入框架
  2. 去到項(xiàng)目的build phases 設(shè)置項(xiàng),找到MapKit.framework.并加入到Link Binary With Libraries里面。如果使用modules的話,只需要加入語句 "@import MapKit;" 你就可以開始使用了,根本不需要鏈接到你的項(xiàng)目。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容