Xcode6 about PCH files

Source: Internet
Author: User

Create a project before xcode6. The system will automatically create a PCH (precompile header) file named by the project name. A file named-Prefix will be displayed under the supporting files file. the file ending with PCH. PCH is the "precompiled header", that is, the pre-compiled header file. Some codes that are not frequently modified in the project stored in the file, such as common framework header files, during the development process, the compiler will automatically add the header files in the PCH file to all the source files by including the header files that are widely used throughout the project, in this way, you can directly use the content in the header file without using import when you need to use the relevant classes, which brings convenience to programming, but also brings some potential problems, this is why PCH is no longer created by default in xcode6.

In my opinion, the main reason why xcode 6 removes the precompile prefix header is:

(1) removing the header file of the automatically imported system framework class library can improve the reusability of the original file and facilitate migration.

(2) A obese prefix header will greatly increase the Compilation Time.

To replace the framework automatically imported in the prefix header, you can use @ import to manually import the framework in each file to import the system framework. Of course, make sure that enable modules in build settings is enabled.

If <objc/runtime. h>, we can get the <objc/runtime for free in every file of the project. h> the right, without having to manually in every. h /. import <objc/runtime. h>. This file is indeed convenient.

If precompile prefix header is required, how can I configure precompile prefix header in xcode6 and add a PCH file?

(1) command + N, open the new file window: IOS-> Other-> PCH file, create a PCH file, remember the name of the file you created (it is best to name it "project name-prefix. PCH "form name, such as a-Prefx.pch), and so on the configuration path to use:

For example, the PCH file name is daidaifa. PCH.

,

(2) Set build settings and configure some information (the PCH file name must be the same as the PCH file name at the time of creation when the path is configured ):

 

New as a new a-Prefix.pch File

Note: When you switch the precompile prefix header, the PCH compilation and import mechanisms are very different.

 

 

 

Some may have some questions about the value of precompile prefix header (Yes/No). Here we will explain:

(1) If the precompile prefix header is yes, PCH will be pre-compiled, and the pre-compiled PCH file will be cached to speed up compilation. (2) If the precompile prefix header is no, PCH will not be pre-compiled. Instead, it will be compiled once in every. M file of the framework class library used for its import, reducing the compilation speed. For example, the a-Prefix.pch imports <objc/runtime. h>, viewcontroller. m and appdelegate. the objc_property_t type is used in M (note viewcontroller. h/m and appdelegate. h/m has not been separately imported <objc/runtime. h>). In the build process, compile viewcontroller. m and appdelegate. m, the a-Prefix.pch will be compiled twice, each. the M file is compiled once.

If the precompile prefix header is no, every. M file that references PCH must be compiled once. Apple may also implement a caching mechanism, but this reduces the compilation speed.

Since we do not need PCH for Apple standards, try to use it as little as possible. Of course, if necessary, we should try to reduce the content in the PCH file, reduce the project's dependency on the PCH file, and facilitate future migration and decoupling.

 

Xcode6 about PCH files

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.