添加pch文件

Xcoe6前系统会帮我们自动新建一个以工程名为名字的pch (precompile header)文件,之后的版本就要自己手动创建了。

添加pch文件_第1张图片
pch文件.png

接下来在build Settings 中搜 prefix Header然后添加路径即可
(PS: $(SRCROOT) 用来表示相对路径),输入后会变成本地的绝对路径


srcroot.png
添加pch文件_第2张图片
路径配置.png

如上图,然后在pch文件中import所需的头文件即可
至于其引起的问题、官方文档有给出(如下,具体还未看,复制到别人的),因此不再自动创建,但是这功能实在很方便,所以还是使用了……

As to where to put code that you would put in a prefix header, there is no code you should put in a prefix header. Put your imports into the files that need them. Put your definitions into their own files. Put your macros...nowhere. Stop writing macros unless there is no other way (such as when you need FILE). If you do need macros, put them in a header and include it.

The prefix header was necessary for things that are huge and used by nearly everything in the whole system (like Foundation.h). If you have something that huge and ubiquitous, you should rethink your architecture. Prefix headers make code reuse hard, and introduce subtle build problems if any of the files listed can change. Avoid them until you have a serious build time problem that you can demonstrate is dramatically improved with a prefix header.

In that case you can create one and pass it into clang, but it's incredibly rare that it's a good idea.

你可能感兴趣的:(添加pch文件)