在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這個框架,你要這樣做
- 使用語句 #import <MapKit/MapKit.h> 導入框架
- 去到項目的build phases 設置項,找到MapKit.framework.并加入到Link Binary With Libraries里面。如果使用modules的話,只需要加入語句 "@import MapKit;" 你就可以開始使用了,根本不需要鏈接到你的項目。