I do not understand how Xcode knows which headers should be included into which target? For example if I add a new File to my Xcode Project it adds the .m File to the compile sources of the selected targets but what about the .h files? How does my target know which header files should be used?
Asked
Active
Viewed 681 times
1 Answers
4
Only .m files and resource files are part of the targets, not .h. 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.
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).
Just to give an example via screenshot, the way we control headers in Xcode for libraries is in build phase something like this:
You may further read out this Apple Documentation for setting the visibility of header files in Xcode.

Abhinav
- 37,684
- 43
- 191
- 309
-
Okay, that helps me understanding this a little bit better. If don't add my new files to the target they wont be accessible inside classes from that target right ? How does XCode know about this and how can i change that later ? – Sebastian Boldt Oct 22 '15 at 11:44
-
If you, somehow, forget to add a new file in a specific target and that file is being used by some other file in the same target, Xcode will start complaining. To fix that, you need to select your project file (top in project navigator), then select the target which has the problem. Select `Build Phase` tab and expand `Compile Sources` section. Tap on + button in bottom part of that section, search and add your missing file. And thats it.... You are all set! – Abhinav Oct 22 '15 at 11:50