1

Using Xcode 9 and Swift 4, I created a bridging header file in order to utilize an external framework but no matter what I do, Xcode ignores the bridging header file. I followed the steps that I found online and I don't what's wrong with the project. I attached an image, shouldn't this give me a compilation error since there are invalid characters in the header file?

Click to see Xcode project image

This is not a duplicate question, that question that was suggested has issues making the header file work because of compile errors, in my situation compilation is successful and Xcode doesn't even try to compile the header file.

I created another project from scratch and I was able to make the bridging header work so I guess there is something wrong with this project. I create this project and try again.

Christophe
  • 68,716
  • 7
  • 72
  • 138
Rif
  • 11
  • 4
  • do you want to see the errors or bridge your project ? Have you tried to import your libs to see if it works ? – GIJOW Apr 16 '18 at 14:30
  • Try to clear the Derived data, clean project, close xCode, launch again –  Apr 16 '18 at 14:32
  • Cleared the Derived data, cleaned project and restarted Xcode, build succeeds even the bridge file has bad content. When I add the proper import into the bridging header, I can't use it in Swift, it says undeclared type, that's why I got the idea that Xcode doesn't use the bridging file at all for some reason. Another thing I tried was, I changed the file in Build Settings to broken path, Xcode still succeeds the build. – Rif Apr 16 '18 at 14:58
  • Is your bridging header automatically generated by Xcode, or did you create your own? – koen Apr 16 '18 at 15:09
  • I tried both ways, automatic and manual, the result has been the same. – Rif Apr 16 '18 at 15:30
  • Possible duplicate of [Failed to import bridging header](https://stackoverflow.com/questions/26116288/failed-to-import-bridging-header) – koen Apr 16 '18 at 15:44

4 Answers4

3

I found out that creating objective-c file instead of directly creating header file is more convenient.

You can try to create a dummy objective-c file.

From Xcode's file menu click File-> New-> File. Choose Objective-C File and click next button.

You can give any dummy name you want. I gave the name as DummyFile.

new objective-c files

Click Next.

Now save this file in the project's directory.

As Xcode is about to add this Objective-C file to your Swift project is automatically asks you to create a Bridging Header as shown below.

[Xcode's bridging header creation option[2]

As you click Create Bridging Header, Xcode creates a Brigder-Bridging-Header.h file (As my project name is "Bridger") and put it in the project's directory as shown in Xcode's project navigation pan.

Bridging header file.

Now you can import your target's public headers that you would like to expose to Swift.

You can now delete the DummyFile.m from the project's directory if you want.

And this should work as wished.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Ratnesh Jain
  • 671
  • 7
  • 14
2
Project > Build Settings > SWIFT_OBJC_BRIDGING_HEADER

Have you specified the Bridging header file name here?

pkamb
  • 33,281
  • 23
  • 160
  • 191
BXV
  • 405
  • 3
  • 16
  • I just added to Project -> Build Settings as well as Target -> Build Settings, cleaned the project and the result is the same – Rif Apr 16 '18 at 15:04
1

As Biju said, specify Bridging header file name - try changing its location (e.g. put it inside project folder)

Kowboj
  • 351
  • 2
  • 14
0

Perform a clean build by cleaning first (Command + K) and then Building (Command + B).

Had the same issue and this fixed it.

Mohamad Bachir Sidani
  • 2,077
  • 1
  • 11
  • 17