转自:http://www.jianshu.com/p/e6e0e3bbbf38点击打开链接
1.) 打开你的Xcode工程. 在Supporting Files目录下,选择 File > New > File > iOS > Other > PCH File 然后点击下一步;
2.) 假设你的项目名称为TestDemo, 你的PCH 文件的名字建议为TestDemo-Prefix.pch,然后创建;
![](https://i-blog.csdnimg.cn/blog_migrate/9a2ec33dca2a7c1adcbb78cd2a300360.webp?x-image-process=image/format,png)
3.) 选择 PCH 文件(文章的示例文件为 TestDemo-Prefix.pch) ,可以看到里面的内容如下:
![](https://i-blog.csdnimg.cn/blog_migrate/a835dfeb0a3fc3ba86324ff3835eadf5.webp?x-image-process=image/format,png)
4.) 找到 Project > Build Settings > 搜索 “Prefix Header“;
5.) “Apple LLVM 8.0 -Language″ (配图是Xcode7, 7和8是一样的)栏目中你将会看到 Prefix Header 关键字;
6.) 输入: TestDemo/TestDemo-Prefix.pch (如 TestDemo/TestDemo-Prefix.pch );如果你的pch文件名为TestDemo.pch, 那么这里就应该为TestDemo/TestDemo.pch
7.),将Precompile Prefix Header为YES,预编译后的pch文件会被缓存起来,可以提高编译速度。效果如下
![](https://i-blog.csdnimg.cn/blog_migrate/3c31e0bd1aea638b3bbe6ad68047a5ce.webp?x-image-process=image/format,png)
8.) Clean 并且 build 你的项目
就是这样!Done!现在你可以使用你的 PCH 文件就像你使用老版本的Xcode一样了