IOS pch file details

Source: Internet
Author: User

IOS pch file details

After Xcode6, including the current Xcode7, The. pch file will not be generated automatically. It seems that it is no longer recommended. However, when looking at many other projects, this file is still included. Let's talk about what. pch is today.

* ** _ Prefix. pch is the pre-compiled header file of the project .. Pch indicates the PreComplied Header, which is a list of Header files from the external framework used by a project. Xcode will first compile these header files in. pch to reduce the time needed to Build the entire project. Generally, all files automatically contain the pch file. The system first imports this file before compiling every. h and. m file, instead of compiling the header files in each file separately. The compilation process is accelerated.

What should we do if we accidentally delete the. pch file? You can create another PCH File by yourself. The name can be any one. Then, go to Build Setting in the Project Settings, and enter "pch" in the search box in the upper right corner to find a Prefix Header, and enter the modified name. Note that this is a relative path.

.

 

.

 

So sometimes we often include many common header files in pch. For example, the following is one of my pch files:

 

#ifndef MyPass_pch#define MyPass_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.#import AppDelegate.h#import 
 
  #import AppDelegate.h#endif /* MyPass_pch */
 

 

In this way, we do not need to include these three header files in all. h and. m files. But please note !!!!!! One exception !!!!!

# Import in the AppDelegate. h file of the iOS Project It cannot be missing. This is because the AppDelegate. h file is the Startup file of the entire project and is compiled earlier than the pch file. Therefore, the header files required in AppDelegate. h cannot be placed in pch.

I explained how to define constants in the project in the previous blog "Best practices for defining constants in iOS". Now with the pch file, it is very convenient. We can define the # define macro In the pch file. The macro definition can be used anywhere in the project. It is very convenient to explicitly introduce the pch file. Unfortunately, the const constant cannot be defined in pch...

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.