在ios 7下,使用@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导入框架,2) 去到项目的build phases 设置项,找到MapKit.framework.并加入到Link Binary With Libraries里面。如果使用modules的话,只需要加入语句 "@import MapKit;" 你就可以开始使用了,根本不需要链接到你的项目。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • modules和 auto-linking 这两个新特性。用 @import 来增加框架 到项目中比用 #impo...
    edison0428阅读 334评论 0 1
  • 在xcode 5 下,为了更易于开发,增加了modules和 auto-linking这两个新特性。用@impor...
    大风天上来阅读 749评论 0 0
  • 宋代有诗云:“自从陆羽生人间,人间相学事春茶”。 陆羽(733—804),字鸿渐,一名疾,字季疵。唐复州竟陵(今湖...
    晴溪阅读 1,751评论 0 7
  • 安娜四岁这天,夏日的阳光正毫不吝啬地炙烤着七月的大地,大人们都躲进门窗关得密密实实的空调房里,只有这群身体里迸发着...
    chaos_theory阅读 381评论 0 2