iOS7下,使用@import代替#import

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

"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 默認情況下是enabled的。 如果是舊的項目,你可以通過設置"Language - Modules." 來設置Enable Modules 和Link Frameworks Automatically 為Yes。


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

  1. 使用語句 #import <MapKit/MapKit.h> 導入框架
  2. 去到項目的build phases 設置項,找到MapKit.framework.并加入到Link Binary With Libraries里面。如果使用modules的話,只需要加入語句 "@import MapKit;" 你就可以開始使用了,根本不需要鏈接到你的項目。
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容