前言
在xcode6之前,每次创建工程,在工程的目录里都会为我们创建“工程名+Prefix.pch”文件,这是一个头文件,和.h文件不同,不需要导入到其他的类中。pch文件中的内容可以在工程的所有源文件中使用。
xcode6之后再创建工程,pch文件就默认不存在了,可能是因为pch文件大大增加了工程编译的时间,具体原因可以看这里。
那么现在我们再如何在xcode8中添加pch文件呢?
1、创建PCH文件
Command+N,打开新建文件窗口:iOS->other->PCH file,创建一个pch文件:“工程名-Prefix.pch”

2、添加PCH文件路径
将building setting中的prefix header选项的路径添加“$(SRCROOT)/项目名称/pch文件名”(例如:$(SRCROOT)/OCStudy0106PCH/PrefixHeader.pch)

注:$(SRCROOT)的意思就是工程根目录的意思
3、将Precompile Prefix Header为YES
预编译后的pch文件会被缓存起来,可以提高编译速度

网友评论