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