Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Prefix.pch best practices

I have seen many developers that add various convenience macros to the Prefix.pch of their iOS projects.

What do (or don't) you recommend adding to the iOS Prefix.pch file? What does your Prefix.pch look like?

like image 411
hpique Avatar asked May 16 '10 19:05

hpique


People also ask

What is PCH file in iOS?

pch is a precompiled header. Precompiled headers were invented to make compiling faster. Rather than parsing the same header files over and over, these files get parsed once, ahead of time.

What is PCH file?

In computer programming, a precompiled header (PCH) is a (C or C++) header file that is compiled into an intermediate form that is faster to process for the compiler.

How do I add PCH files to Xcode 10?

From your Xcode menu, select File > New > File... From iOS template options, select Other > PCH file. Name the file <target_name>-Prefix. pch, and then select Create.


1 Answers

Ewww… 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.

like image 88
bbum Avatar answered Sep 22 '22 13:09

bbum