11
votes

I'm developing an iPhone app in Xcode 4.6.2 that only has one target, and I've noticed that some important files are not members of my target. None of my custom header files are part of the target membership, nor is my Info.plist, my Prefix header, or the product "MyApp.app."

The way I understand targets, these files certainly need to be members of the target.

My question is: why aren't these files members of my target?

After searching around on SO, similar questions have yielded some insight, but not a complete answer to that question. The insight I've gathered is:

  1. Header files are not members of your target because they get linked in the "Copy Headers" Build Phase.

    • This sounds reasonable, but I don't have a Copy Headers Build Phase
  2. Info.plist and Prefix.pch aren't members of the target because Info.plist gets linked in the "Copy Bundle Resources" Build Phase, and the Info.plist contains a key/value entry that points to the prefix header (Prefix.pch)

    • I'm not positive that this is actually how it works
3

3 Answers

16
votes

Header files are what other source files reference so that they know what the interface for a class is. They aren't needed as part of the binary itself, so they don't need to be included in the final product.

Info.plist is a special case as it defines the application bundle itself, so it is processed separately.

Generally speaking, you want files to be members of your target when they:

  • Form part of the executable (e.g. implementation (.m) files or libraries), or
  • Are included as files in the application bundle (e.g. images).

You don't need files to be members of your target if they are only used as part of the build process and aren't needed at runtime. Typically this is any type of header file, including precompiled headers (.pch).

3
votes

Only .m files and resource files are part of the targets, not .h.

You are right: the Info.plist files and the headers are all referenced in the build settings (which again are target specific).

3
votes

Headers only need to be copied for a framework target, and only because they are part of the framework release (they allow users to know how to use the framework). Apps don't need the headers because they're compiled stand alone entities. The headers (and the pch file) are used during compilation but aren't required at runtime.

The info.plist is handled differently. It usually can't just be copied because in the project it usually isn't called "Info.plist". It's also mandatory for the file to exist in the app so Xcode doesn't give you the option of not including it.