How does the target know which headers it should include?

776 views Asked by At

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?

1

There are 1 answers

2
Abhinav On BEST ANSWER

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:

enter image description here

You may further read out this Apple Documentation for setting the visibility of header files in Xcode.