1、pch作用:
存放全局的宏、头文件、能自动打开或者关闭日志输出功能.
2、在Xcode中添加pch文件,只需要三步:
<1>Command+N,打开新建文件窗口:iOS->other->PCH file,创建一个pch文件:

<2>在工程的TARGETS里边Building Setting中搜索Prefix Header,然后把Precompile Prefix Header右边的NO改为Yes,预编译后的pch文件会被缓存起来,可以提高编译速度:

<3>在Precompile Prefix Header下边的Prefix Header右边双击,添加pch文件的工程路径,添加格式:“$(SRCROOT)/项目名称/pch文件名” ,$(SRCROOT)的意思就是工程根目录的意思。如果不清楚的话可以右键pch文件,然后show in finder:

红色圈出来的就是$(SRCROOT),也就是工程的根目录,绿色圈出来的是项目名称和pch文件名,所以完整的pch文件的路径就是:$(SRCROOT)/loginceshi/pch/PrefixHeader.pch,添加路径:

添加完成后,会自动帮你变成你工程所在的路径:

简单的三步,这样就配置完成了,编译一下程序,如果有错误检查一下添加的路径是否正确。
网友评论