1、好处ios
One of the big advantages of using @import
is that you don't need to add the framework in the project settings, it's done automatically. That means that you can skip the step where you click the plus button and search for the framework (golden toolbox), then move it to the "Frameworks" group. It will save many developers from the cryptic "Linker error" messages.sql
使用@import的最大好处之一是当须要使用某个苹果本身的框架时,不再须要在项目的setting中作 "点击'+'号按钮搜索依赖框架添加" 这样的操做了,@import内部会自动实现这个过程。这样咱们就可使用代码完成之前须要在图形界面完成的动做。苹果又为开发者作出了改进。app
之前写程序导入系统头文件的时候都这么写#import <Cocoa/Cocoa.h>,
如今你多了一种选择, 你能够这么写:@import Cocoa; 而且免去了添加框架的操做。
框架
2、局限性性能
Modules only work with Apple frameworks (UIKit, MapKit, GameKit, etc). You can't use them with frameworks you create yourself. Currently you can't use them with 3rd-party frameworks (AFNetworking, RestKit, MagicalRecord). I don't think it works with non-Apple frameworks even if they're included in Xcode (dylibs like libsqlite3.dylib).ui
可是目前使用@import仅适用于苹果本身的框架,当在项目中想使用@import导入本身搭建的框架或者第三方框架时,是无效的。spa
3、实际开发中翻译
You don't actually need to use the @import
keyword. If you opt-in to using modules, all #import
and #include
directives are mapped to use @import
automatically. That means that you don't have to change your source code (or the source code of libraries that you download from elsewhere). Supposedly using modules improves the build performance too, especially if you haven't been using PCHs well or if your project has many small source files.code
实际开发中上可能并不须要使用@import关键字。若是你选择使用"modules"(Xcode5中默认开启),全部的#import和#include 指令都会自动映射使用@import。这意味着你并不须要改变你以前的源码。下面意译, 尤为对于没有善用.pch头文件的开发者或者你的项目中有许多零碎小的源文件时, 使用@import导入指定框架下须要的头文件时,Xcode的编译表现会有提升。orm
读完这篇回答我我的的理解就是, 苹果再次针对开发者常常会遇到的问题作出了改进,提供了图形化操做以外的代码方式添加框架的选择, 更加的灵活人性。固然可能@import在实际开发中并不会对工做有多少帮助,善于使用pch文件而且尽可能避免零碎的小文件, 项目的总体编译性能才会有提高。
这篇回答自己英文并不难理解,原本没想翻译,可是想到可能会有一样疑惑的开发者,因而便将主要内容翻译出来,本身印象也深入一点,有翻译不到位或者理解错误的地方还请纠正。
原文出处:
http://stackoverflow.com/questions/18947516/import-vs-import-ios-7