再谈PCH预编译文件

何为pch文件?

pch全称是“precompiled header”,也就是预编译头文件,在该文件中存放的是工程中一些不常被修改的代码,比如常用的框架头文件或者一些宏定义的URL地址、log输出开关控制,在release版本里面不需要输出。在这里面定义后可全局使用。

Xcode6为何取消pch文件?

pch文件在Xcode6之后就不再默认创建。至于为什么不默认创建呢,请参看StackOverFlow上得这篇文章

如何手动添加?

  1. 新建工程后,新建文件,选择其他-PCH File
  2. 创建完成后,就可以看到我们的PCH文件了,内容如下:
//

//  PrefixHeader.pch

//  PCHDemo

//

//  Created by zhaoxiangguang on 15/8/3.

//  Copyright (c) 2015年 Awnlab.com. All rights reserved.

//

#ifndef PCHDemo_PrefixHeader_pch

#define PCHDemo_PrefixHeader_pch

// Include any system framework and library headers here that should be included in all compilation units.

// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.

#endif

下一步如何配置?

在Build Settings中搜索prefix header,双击Prefix Header后输入$(SRCROOT)/PCHDemo/PrefixHeader.pch或者输入相对路径PCHDemo/PrefixHeader.pch,其中PCHDemo为工程名字,PrefixHeader.pch为预编译头文件名称。

填写完成后在PrefixHeader文件中加入我们的宏,这样在全局中我们都可以使用了。

 

尊重原创内容,转载请注明出处
本文链接地址: https://www.awnlab.com/archives/23

为您推荐

发表评论

邮箱地址不会被公开。 必填项已用*标注