How to add .pch or Prefix.pch file in Xcode 6?


What is .pch file?
PCH is stand for Pre-Compiled Header. Prefix headers will compiled and stored in a
cache during compilation and include in each and every file rather than parsing same file multiple
times. As Prefix header parsed only once it make compilation fast.

Overview:~

As you start using Xcode 6 and created new project you realize that, new version of Xcode is not creating <ProjectName>-Prefix.pch file for your project. But don’t worry about that as you can create .pch file for your project any time.

Steps to add PCH file in our project :~

1.) Open your existing project in Xcode. Select File > New > File > iOS > Other > PCH File and click Next.

.pch file

How to add .pch file in Xcode6

2.) Give the name to your PCH file like projectName-Prefix.pch. For example if your project name is iOSSample then PCH file name will be iOSSample-Prefix.pch and click on create button.

3.) Select the PCH file (in our case its iOSSample-Prefix.pch) and replace its content with following.

//
// Prefix header
//
// The contents of this file are implicitly
// included at the beginning of every source file
//

#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

4.) Goto Project > Build Settings > Search for “Prefix Header

5.) Under “Apple LLVM 6.0” you will get the Prefix Header key.

How to add .pch file #2

How to add .pch file #2

6.) Type in: YourProjectName/YourProject-Prefix.pch or $(SRCROOT)/YourProject-Prefix.pch

7.) Clean and build your project.

That’s it. Done. Now you can use your PCH file as you were doing in your old Xcode version.

6 thoughts on “How to add .pch or Prefix.pch file in Xcode 6?

  1. I am trying this tutorial but while running the project i am getting linker error while placing any parameter in the .pch file
    I am using IOS sdk 8.4
    please help me to resolve the issue

    Like

Leave a reply to Asif Cancel reply