@import--iOS7新關鍵字

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

相關文章
相關標籤/搜索