How to add a PCH file in xcode6

Source: Internet
Author: User

Before xcode6, when creating a project, the system will automatically create a PCH (precompile header) file named by the project name. during the development process, the compiler automatically adds the header files in the PCH file to all source files by including the header files widely used in the entire 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.

About PCH's gains and losses, stackoverflow has a paragraph to talk about more thoroughly: http://stackoverflow.com/questions/24158648/why-isnt-projectname-prefix-pch-created-automatically-in-xcode-6

 

As to where to put code that you wocould put in a prefix header, There is no code you shoshould put in a prefix header. put your imports into the files that need them. put your definitions into their own files. put your macros... nowhere. stop writing macros unless there is no other way (such as when you need _ file __). if you do need macros, put them in a header and include it.

The prefix header was necessary for things that are huge and used by nearly everything in the whole system (like Foundation. h ). if you have something that huge and ubiquitous, you shoshould rethink your architecture. prefix headers make code reuse hard, and introduce subtle build problems if any of the files listed can change. avoid them until you have a serious build time problem that you can demonstrate is dramatically improved with a prefix header.

In that case you can create one and pass it into clang, but it's incredibly rare that it's a good idea.

 

But sometimes the PCH file is still needed. How can I add a PCH file in xcode6?

First, Run Command + n to open the new file window: IOS-> Other-> PCH file, create a PCH file, and add the header file name to be introduced:

 

 

 



 

Second, modify the project configuration file and add the path of the just-created PCH file to the precompile header option in building setting. Note that both the debug and release columns must be added:

 

 

Now, compilation is complete, and the newly added PCH file can be used normally.

How to add a PCH file in xcode6

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.