Fix: ProjectName-Prefix.pch Not Created Automatically in Xcode 6

Fix: ProjectName-Prefix.pch Not Created Automatically in Xcode 6

Written by

in

Quick answer: Xcode 6 introduced modules which eliminated the need for prefix headers. Modern practice is to import frameworks directly in each file. If you still need a PCH file, create it manually via File > New > File > Other > PCH File and configure Build Settings.

Why this happens

Xcode 6 introduced modules (via @import syntax) which fundamentally changed how system frameworks are imported. Modules provide faster builds, better encapsulation, and automatic linking — removing the primary reason prefix headers existed: pre-compiling massive headers like Foundation.h or UIKit.h across every source file.

With modules, each file imports only what it needs. The compiler no longer needs a shared precompiled header to achieve good build performance. Apple’s templates were updated to reflect this, so new projects no longer include a ProjectName-Prefix.pch file by default.

Prefix headers also created hidden dependencies. When a PCH imports a framework, every file in the target implicitly depends on it, making code reuse harder and causing subtle build breakage when the PCH changes. The modern approach makes dependencies explicit.

How to fix it

1. Adopt modern import practices (recommended)

Remove any reliance on a prefix header. In each Swift or Objective‑C file, import only the frameworks and headers you actually use.

Swift — use import statements at the top of each file:

import UIKit
import Foundation
import MyCustomFramework

Objective‑C — prefer the module syntax (@import) which is faster and handles linking automatically:

@import UIKit;
@import Foundation;
@import MyCustomFramework;

// Or traditional #import when a module isn't available
#import "MyCustomHeader.h"

If you have constants, macros, or category extensions that were previously in the PCH, move them to dedicated header files and import those headers only where needed. For example, create AppConstants.h or UIViewController+HUD.h and import them in the specific view controllers that require them.

2. Manually add a PCH file (only if necessary)

If you have a legitimate case — such as a massive legacy codebase where adding imports to hundreds of files isn’t feasible yet — you can create a prefix header manually.

  1. In Xcode, choose File > New > File… (⌘N).
  2. Under Other, select PCH File and click Next.
  3. Name it (e.g., MyPrefixHeader.pch) and save it inside your project folder.
  4. Open the target’s Build Settings tab.
  5. Search for Prefix Header (GCC_PREFIX_HEADER). Set its value to the path relative to the project root, for example:
    $(PROJECT_DIR)/MyProject/MyPrefixHeader.pch
    Using $(PROJECT_DIR) or $(SRCROOT) makes the path portable across machines.
  6. Search for Precompile Prefix Header (GCC_PRECOMPILE_PREFIX_HEADER) and set it to Yes.
  7. In your new .pch file, add only the truly ubiquitous imports:
    objc
    #ifdef __OBJC__
    @import UIKit;
    @import Foundation;
    #endif

Warning: Avoid putting app‑specific macros, categories, or third‑party headers in the PCH. Doing so recreates the hidden‑dependency problems modules were designed to solve.

How to prevent it

  • Default to explicit imports in every new file. Xcode’s file templates already do this.
  • Audit existing PCH usage when migrating older projects: move each import to the files that actually need it.
  • Use modules (@import) for all system frameworks; they’re faster and avoid duplicate‑symbol issues.
  • Resist adding a PCH unless profiling shows a measurable build‑time regression that only a precompiled header can fix.
  • Keep shared code in proper modules or Swift packages rather than dumping it into a prefix header.

FAQ

### Does Swift use prefix headers?

No. Swift relies entirely on import statements and module maps. There is no Swift equivalent of a .pch file, and bridging headers serve a different purpose (exposing Objective‑C APIs to Swift).

### Will adding a PCH break Swift files in the same target?

No. The prefix header only applies to Objective‑C, Objective‑C++, C, and C++ compilation. Swift files ignore it completely.

### Can I use a PCH to share Swift constants across the app?

Not directly. Define shared Swift constants in a dedicated Constants.swift file (or a Constants enum/struct) and import the module where needed. For Objective‑C constants needed in Swift, expose them via the bridging header.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 3.0; this article is shared under the same license.