Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6072619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:10:48+00:00 2026-05-23T10:10:48+00:00

While learning iPhone programming, every Xcode template I’ve seen includes an AppName-Prefix.pch file with

  • 0

While learning iPhone programming, every Xcode template I’ve seen includes an AppName-Prefix.pch file with the following contents:

#ifdef __OBJC__
    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
#endif

My understanding is that this file’s contents are prefixed to each of the source code files before compilation. Yet each of the other files also imports UIKit, which seems superfluous. For example, main.m begins…

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {
...

Cocoa applications in Mac OS X do the same thing, importing Cocoa.h in both the prefix file and the header files.

Why have both? I removed the #import directives from all of the source files except the prefix file, and it compiled and ran correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:10:49+00:00Added an answer on May 23, 2026 at 10:10 am

    My understanding is that this file’s contents are prefixed to each of the source code files before compilation

    That’s basically correct but you need to understand the subtle points: Every compilation from Xcode eventually boils down to an invocation of gcc or clang. What XCode does is to compile the X.pch file first:

    clang -x X.pch -o X.pch.gch
    

    and then when an individual source file (say a.m) is compiled, it issues

    clang -include X.pch a.m -o a.o
    

    which loads the pch file, triggering the use of the precompiled header. So, from the point of view of the compiler, it’s not really that the content of the pch file is automatically prefixed. Rather, Xcode prefixes the precompiled header to a file when it invokes the compiler.

    A future version of XCode might just stop doing it. So, it’s better to keep #imports in your .m or .h files, too.

    You can also think of it this way: the use of the pch file is just what Xcode does for us behind the scenes to speed up the compilation process. So, we shouldn’t write codes in a way it essentially depends on it, like not importing UIKit.h file from our .m/.h files.

    (Also, it seems to me that XCode4’s syntax coloring gets confused if you don’t import the appropriate header files correctly from the .h and .m files.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've slightly modified the iPhone SDK's GLSprite example while learning OpenGL ES and it
While learning different languages, I've often seen objects allocated on the fly, most often
I am beginner to freeswitch.While learning this I have seen the terms 'leg A'
While learning on anonymous methods, i've found the following example on the internet: namespace
I am trying to program (while learning JQuery) the following: I have a form
while learning some basic programming with python, i found web.py. i got stuck with
While learning Prolog, I'm trying to solve the following problem, using accumulators: Write a
While learning to use LINQ in VB.NET, I came across the following: Dim x
While learning the concept of copying members, the book gives the following statement. In
While learning iOS programming from a book, I notice that for long lines of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.