在ios7下,使用@import代替#import

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

在xcode 5 下,为了更易于开发,增加了modules和 auto-linking 这两个新特性。用 @import 来增加框架 到项目中比用 #import会更有效. 我们来看看为什么:

"Modules for system frameworks speed build time andPRovide 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;" 你就可以开始使用了,根本不需要链接到你的项目。

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航