Xcode Precompile Prefix Header analysis, xcodeprecompile

Source: Internet
Author: User

Xcode Precompile Prefix Header analysis, xcodeprecompile

You can see the Precompile Prefix Header in the template project of Xcode 4 and 5, but it is castrated in Xcode 6. For the reason, refer to the following two links:

Http://stackoverflow.com/questions/24158648/why-isnt-projectname-prefix-pch-created-automatically-in-xcode-6

Http://blog.csdn.net/lihuiqwertyuiop/article/details/39268101#comments


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 Build 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.


Therefore, if you must use the Precompile Prefix Header, you can refer to Xcode 5 configuration to manually set it.
(1) Add a pch file in the project, naming is better according to Xcode 5 template: Project name-Prefix. pch, such as a-Prefx.pch
(2) Set Build Settings

The Prefix Header specifies the position of the pch file.



Note: When you switch the Precompile Prefix Header, the pch compilation and import mechanisms are very different.
If the Precompile Prefix Header is YES, pch will be pre-compiled, and the pre-compiled pch file will be cached to increase the compilation speed. We can see from the Build Log below:



If the Precompile Prefix Header is NO, pch will not be precompiled. Instead, it will be compiled once in every. m file of the framework class library that uses it for import. 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. For example:


The figure shows that if the Precompile Prefix Header is NO, then each Header that references the pch content. the m file must be compiled once for pch. Apple may do another caching mechanism, but this still 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.





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.