@import vs #import - iOS 7

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.

时间: 2024-08-24 15:27:38

@import vs #import - iOS 7的相关文章

@import与#import的使用

在xcode 5 下,为了更易于项目开发,增加了modules和 auto-linking 这两个新特性.用 @import 来增加框架项目中比用 #import会更有效. Modules and auto-linking 默认情况下是enabled的. 如果是旧的项目,你可以通过设置"Language - Modules." 来设置Enable Modules 和Link Frameworks Automatically 为Yes.   另外一个使用moudules的好处是你再也不用

#import、#include、#import&lt;&gt;和#import””的区别

#import.#include.#import<>和#import””的区别 一.#import与#include #import不会引起交叉编译的问题.因为在Objective-C中会存在C/C++和Object-C混编的问题,如果用#include引入头文件,会导致交叉编译. 二.#import<>与#import"" 在实际运用中都是某个框架里的.#import <Three20/Three20.h><>通常指向的是一个目录#im

from module import 和 import 的区别

最近在用codecademy学python,遇到一些题目错误,小小记录一下 如from math import sqrt是把sqrt作为本文件的方法导入进来了,使用的时候只需要直接调用sqrt. 而如果import是import math,那么调用的时候要采用math.sqrt的方式. 那么如果在自己的文件里定义了相同名字的函数怎么办呢,来实验一下 1 2 3 4 5 from math import sqrt  def sqrt(n):      return n  print sqrt(13

浅议package、import、import static

我们也许知道,Java引入包机制,提供了类的多层命名空间,解决了类的命名冲突.类文件管理等问题.但是总会出现一些问题. 问题一 E:\Demo\java  中的文件有:Zi.java.Test.java两个文件 Zi.java中代码如下: public class Zi  { public void print() { System.out.println("abc"); } } Test.java中代码如下: import com.Zi; public class Test { pu

package、import和import static

package 语句: 该语句必须作为源文件的第一条非注释性语句,一个源文件只能指定一个包,即只能包含一条package语句. import 和import static 关键字: 引入import关键字是为了简化编程.如果没有import关键字的存在,那么如果我们在实例化另一个包中的类时,必须指明其所在的位置. 例如:java.io.InputStream is = new java.io.InputStream. import static静态导入是JDK1.5中的新特性.一般我们导入一个类

python 模块导入import和import from区别

模块就是一个.py文件,在名字空间下导入模块导入import和import from,那么python 模块导入import和import from区别是什么呢 1,import 导入模块 import 模块名 print(模块名.方法) 2,import 模块名 from 方法1,方法2 调用方法  print(方法1) 注意 import 模块名 as 别名 文章来自 www.96net.com.cn 原文地址:https://www.cnblogs.com/96net/p/9743742.

day28 import,from * import *,__name__

Python之路,Day16 = Python基础16 一 module通常模块为一个文件,直接使用import来导入就好了.可以作为module的文件类型有".py".".pyo".".pyc".".pyd".".so".".dll". 二 package通常包总是一个目录,可以使用import导入包,或者from + import来导入包中的部分模块.包目录下为首的一个文件便是 __

java中import机制(指定import和import *的区别)

java中有两种包的导入机制,总结如下: 单类型导入(single-type-import),              例如 import java.io.File; 按需类型导入(type-import-on-demand),例如 import java.io.*; 这里分析一下这两种导入类型的大致工作原理供大家参考. 单类型导入比较好理解,仅仅导入一个public类或者接口. 对于按需类型导入(  import java.io.*;   ),有人误解为导入一个包下的所有类,其实不然,看名字

模块import,from ..import...

首次导入模块发生3件事 1.创建一个模块的名称空间 2.执行文件spam.py,将执行过程中产生的名字都放到模块的名称空间中 3.在当前执行文件中直接拿到一个名字,该名字就是执行模块中相对应的名字 from...import.. 优点:使用时,无需再加前缀 缺点:容易与当前名称空间的名字冲突 import 优点:使用时需要加模块名,不会与当前名称空间发生冲突 缺点:但凡应用到模块中的名字都需要加前缀模块名,不够简洁 原文地址:https://www.cnblogs.com/fushaunglin