添加PCH文件

来源:互联网 发布:爱知流量计 编辑:程序博客网 时间:2024/06/05 20:49

建立PCH文件步骤如下:
1.) 打开Xcode工程. 在任意目录或Supporting Files目录下(推荐使用后者),选择 File > New > File > iOS > Other > PCH File 然后点击下一步;

创建PCH--图一

2.) 给你的PCH文件起名字LLPrefix.pch.建议使用你的名字首字母作为前缀,或者根据当前PCH的内容如URL来命名;

3.) 选择 PCH 文件(文章的示例文件为 LLPrefix.pch) ,可以看到里面的内容如下:
与一般的h/m文件完全不同哦!

#ifndef LLUrlHeader_pch#define LLUrlHeader_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 /* LLUrlHeader_pch */

4.) 配置PCH的路径文件中 Project > Build Settings > 搜索 “Prefix Header“(可以直接将pch文件拖到终端会直接得到其路径);

5.) 将Precompile Prefix Header为YES,预编译后的pch文件会被缓存起来,可以提高编译速度;
第四和第五步骤

6.) 将我们在工程中都要用的宏文件或其他.h文件添加到pch文件中,如图所示。此时在.h文件中的宏我们可以直接使用,也可在pch中定义自己需要的宏,这样pch文件也会显得更加的简洁

0 0
原创粉丝点击