zoukankan      html  css  js  c++  java
  • @import vs #import

    It's a new feature called Modules or "semantic import". There's more info in the WWDC 2013 Session 205 & 404 videos. It's kind of a better implementation of the pre-compiled headers. You can use modules with any of the system frameworks in iOS 7 and Mavericks. They are a packaging together of the framework executable and it's headers and are touted as being safer and more efficient than#import.

    One of the big advantages of using @import is that you don't have to add the framework you want 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.

    Also, 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.

    Modules are enabled by default in new projects in Xcode 5. To enable them in an older project, go into your project build settings, search for "Modules" and set "Enable Modules" to "YES". The "Link Frameworks" should be "YES" too:

    You have to be using Xcode 5 and the iOS 7 or Mavericks SDK, but you can still release for older OSs (say iOS 4.3 or whatever). Modules don't change how your code is built or any of the source code. You can't use them for your own frameworks.

    From the WWDC slides:

    • Imports complete semantic description of a framework
    • Doesn't need to parse the headers
    • Better way to import a framework’s interface
    • Loads binary representation
    • More flexible than precompiled headers
    • Immune to effects of local macro definitions (e.g. #define readonly 0x01)
    • Enabled for new projects by default

    To explicitly use modules:

    Replace #import <Cocoa/Cocoa.h> with @import Cocoa;

    You can also import just one header with this notation:

    @import iAd.ADBannerView;

    The submodules autocomplete for you in Xcode.

  • 相关阅读:
    iOS开发之结合asp.net webservice实现文件上传下载
    iOS开发之结合asp.net webservice实现文件上传下载
    底部粘连(stiky footer)布局
    底部粘连(stiky footer)布局
    我在项目中运用 IOC(依赖注入)--实战篇
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    Facebook Libra 白皮书全文:采用拜占庭共识,可扩展至数十亿客户
    DBA遇到问题时的30 个反应,你是哪一种?
  • 原文地址:https://www.cnblogs.com/zsw-1993/p/4879737.html
Copyright © 2011-2022 走看看