13

I followed a tutorial to create a static library project. Then I dragged in my classes and added them to the target.

When I build & run, it creates a libUtils.a file. Upon reveal in Finder the include folder only contains the header file for the first class that Xcode created automatically when I created the project. All other header files are missing.

I double-checked: All the added class files are part of the project and the inspector shows a target membership checkmark for the target project.

Is this a bug in Xcode or must I register all files I create additionally somewhere else?

Proud Member
  • 40,078
  • 47
  • 146
  • 231

2 Answers2

11

Xcode automatically adds a build phase to copy the headers to the product directory. You can add new header files to this build phase:

enter image description here

Update:

You can also use "Copy Headers" build phase instead:

Editor menu > Add Build Phase > Add Copy Headers Build Phase.

And the header files will be added automatically to one of the categories when you add them to the project:

enter image description here

More info about this build phase and the three categories from iOS Developer Library.

Hejazi
  • 16,587
  • 9
  • 52
  • 67
  • Is there a way to tell Xcode to copy them automatically? What is the reason Xcode doesn't do this? Or is it because if you make a library you chose what header is public? – Proud Member Oct 05 '13 at 22:46
  • Actually, the Copy Files phase isn't really required for the library to work correctly (contrary to Compile Sources phase for example), so Xcode is only helping you here by giving an example on how to use Build Phases to copy public header files. – Hejazi Oct 05 '13 at 23:05
  • Ah, but when I don't register all the public headers with Copy Files phase then they don't get exportet to the include directory. So there is other way to get them exportet to include directory when I make a build? – Proud Member Oct 06 '13 at 12:30
  • Yes, there is another better way I think. Check the updated answer. – Hejazi Oct 07 '13 at 22:05
  • 8
    "Copy Headers" -- Apple officially tells you NOT to do this, because they broke this part of Xcode over a year ago and cannot be bothered to fix it. If you want to use it, you MUST use the workarounds (that Apple refuses to document) of making everything "public" and then creating your own RunScript to move them into place – Adam Nov 30 '13 at 13:10
  • @ProudMember it's supposed to. It used to. Then someone at Apple added the new "Archive" menu-function and wrote it badly. Instead of fixing their bad code, they decided to tell people "stop using the Headers system". But Xcode itself doesn't tell you this - so there are many people with broken projects. You have to dig in the updated docs: https://developer.apple.com/library/ios/technotes/iOSStaticLibraries/Articles/creating.html – Adam Nov 30 '13 at 13:12
  • 1
    Don't use this solution, I was sucked for a day with the enterprise distribution because of using this approach in one of my static libraries. – apascual May 20 '15 at 14:59
  • The first answer is right about static library the below screenshot is about cocoa touch framework not static library – codelover Mar 24 '17 at 10:19
3

Add Headers files

Xcode 10.2.1

Project editor -> select a target -> Build Phases -> + Add a new Build Phase -> New Header Phase

enter image description here

The second step is to add .h files

//Build Phases
Project editor -> select a target -> Build Phases -> Headers -> add files to the **public** zone
//or
//Target Membership
Select `.h` file -> Select File Inspectors Tab -> Target Membership -> Select the target and make it **public**

[Target Membership]

yoAlex5
  • 29,217
  • 8
  • 193
  • 205
  • thanks Alex! Other posts are not up to date and there are a lot of answers for older xcode versions... took a while to find yours... – David Thery Feb 14 '21 at 14:22