XCode not making bridging header file?

Hi, I'm trying to add Swift code to my Obj-C project. I've gone through all the tutorials and troubleshooting advice I can find online, no dice. I would appreciate any help, thank you so much in advance.

  1. I add a new swift file to my Obj-C project
  2. XCode offers to create a bridging header file for me, yes please
  3. New .swift file and .h file are added to my project no problem
  4. Header file shows up in build settings no problem
  5. I add a new class to my new swift file ("@objc class HelloPrinter: NSObject")
  6. When I build the app, nothing is generated in the bridging header file and the class is obviously inaccessible to my obj-c code

Is this supposed to work? My understanding is that it's supposed to work.

Somewhat concerning is the text that XCode puts in the bridging header file when it's created: "Use this file to import your target's public headers that you would like to expose to Swift."

I don't want to use this bridging header file for anything. I want XCode to GENERATE STUFF in the bridging file. I also don't want to expose anything to Swift. I want the opposite to happen. So I don't get this text at all. Thanks in advance again.

There are two distinct things here:

  • You can export C or C++ (hmmm objC?) to Swift.
  • You can export Swift to C/C++/ObjC.

It looks like you want to do the latter.

For that, XCode does generate a header but it’s not the file you are looking at in your source tree. It’s a temporary file deep inside the build / intermediates folder structure. The file you are looking at is for exporting in the other direction - as the comment you quoted says - and you can ignore it.

Hopefully that is enough to get you a bit further. You may find previous discussions here if you search for e.g. “bridging”.

This post explains the two headers in play, and explains how to find the one that isn’t the bridging header (gosh I wish that had a better name).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

XCode not making bridging header file?
 
 
Q