What is the Prefix.pch file in Xcode?

So many developers add various convenience macros to the Prefix.pch macro. But my question is what is this Prefix.pch file.

  • If I delete this Prefix.pch file from my Xcode , will my application run? Or will it show any error? Or will this happen during assembly?

  • How to run an application without a Prefix.pch file

+91
ios xcode
May 14 '14 at 7:49
source share
4 answers

Precompiled header.

What is it?

Prefix.pch is a precompiled header. Precompiled headers were invented to speed compilation . Instead of parsing the same header files over and over, these files are parsed once, in advance.

Xcode

In Xcode, you add the import of the header files you want to the โ€œprefix headerโ€ and Precompile Prefix Header precompile the Precompile Prefix Header so that they are precompiled. But the idea of โ€‹โ€‹a prefix header is different than precompilation.

The prefix header is implicitly included at the beginning of each source file. This is how each source file adds

 #import "Prefix.pch" 

at the top of the file before anything else.

Removing it.

You can remove the precompiled header. This question has already been answered in the topic to which I refer below. It contains all the necessary information, as well as useful comments.

Can I remove the Prefix.pch file from an Xcode project?

+107
May 14 '14 at 7:55
source share

What is the Prefix.pch file?

.Pch is a precompiled header.

In the C and C ++ programming languages, the header file is a file whose text can be automatically included by the C preprocessor in another source file, usually determined using the compiler directives in the source file.

Prefix headers are compiled and cached, and then automatically included in each file at compile time. This can speed up compilation and allow you to include the file without adding an import statement to every file that uses it. They are optional, and in fact slow compilation whenever you change them.

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

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

Also note that

Do not put macros in a .pch file! A .pch file is, by definition, a precompiled project-specific header. It really should not be used outside the context of the project, and it should not contain anything other than #include and #imports.

If you have some macros and ones that you want to split between the headers, paste them into your own header file - Common.h or any other - and #include that at the beginning of .pch

+21
May 14 '14 at 7:56
source share

The prefix headers are compiled and stored in the cache, and then automatically included in each file at compile time. This can speed up compilation and allows you to include a file without adding an import statement to each file using it. They are not required, and in fact slow compilation whenever you change them.

Usually generating .pch file .pch is yourProjectName-Prefix.pch

+7
May 14 '14 at 8:08
source share

Precompiled Headers - prefix.pch

Precompiled headers are a partial solution to the slow build problem. They speed up the time it takes to compile a project when all or almost all of the source files must include some common headers. For example, an iOS project is likely to include most, if not all, of the source files. This means repeatedly analyzing and compiling the UIKit.h header when building a project that is wasteful and slow. A precompiled header file, as the name suggests, collects the common headers into a separate file. Pre-compiling this file only once, and then automatically including it in all the source files of the project significantly speeds up the build process for many projects.

Here is a typical Prefix.pch file from an old project that imports UIKit and Foundation headers, and also checks for at least iOS 5:

 #import <Availability.h> #ifndef __IPHONE_5_0 #warning "This project uses features only available in iOS SDK 5.0 and later." #endif #ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #endif 

Being able to include something globally by putting it in a .pch file is a useful but easy to use tool. Maintaining and optimizing the prefix header file also entrusts the developer with a lot of work that the tools should handle.

Now that modules [About] are available, there is no need to continue listing system platforms in the precompiled prefix header . If you need to add a prefix header to your Xcode project, you can still do this by manually changing the Build Settings

  1. Precompile Prefix Header mark YES
  2. specifying the path in the Prefix Header :

Source here

+1
Sep 10 '19 at 10:04
source share



All Articles