Prefix.pch file

看到.pch文件,有一种很生疏的感觉,第一印象根据后缀.pch猜测,还以为是patch的缩写,莫非是什么补丁包?基于不胡乱猜的精神,google了一下,还真不是这个意思,事实证明这是个预编译头文件Pre-Compile Header

答案来源于伟大的stackoverflow,以下是引用:

What is Prefix.pch file?

.pch is a Pre-Compile Header.

In the C and C++ programming languages, a header file is a file whose text may be automatically included in another source file by the C preprocessor, usually specified by the use of compiler directives in the source file.

Prefix headers are compiled and stored in a cache, and then automatically included in every file during compilation. This can speed up compilation, and lets you include a file without adding an import statement to every file using it. They are not required, and actually slow compilation whenever you change them.

Yes, you can compile and run the project without .pch file

In Xcode, go to your target's build settings (Command-Option-E, build tab) and uncheck Precompile Prefix Header (GCC_PRECOMPILE_PREFIX_HEADER). You can also remove the value of the Prefix Header setting if you wish.

Also note that,

Don't put macros in a.pch file! A .pch file is, by definition, a project specific precompiled header. It really shouldn't be used beyond the context of the project and it really shouldn't contain anything but #includes and #imports.

If you have some macros and such that you want to share between headers, then stick 'em in a header file of their own — Common.h or whatever — and #include that at the beginning of the .pch


这里是原始网址:What is Prefix.pch file in Xcode?

你可能感兴趣的:(Prefix.pch file)