Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "file not found" in Bridging Header when importing Objective-C frameworks into Swift project

I have a Swift project for which I'm trying to import ObjC-based frameworks. The framework is located in a directory under the project's path and is referenced by the project in Xcode. It's also added to the "Link Binary with Libraries" in the project's 'Build Phases' page.

However, for some reason, I can't seem to include the framework in the Bridging-Header file. I get the following error:

BridgingHeader.h:5:9: error: 'Parse/Parse.h' file not found #import <Parse/Parse.h>         ^ <unknown>:0: error: failed to import bridging header 'BridgingHeader.h' 

Things I've checked:

  1. The "Install Objective-C Compatibility Header" is set to "YES".
  2. The Header Search Paths includes the path to the frameworks.

I'm sure I'm missing something, so if anyone has any clues, that would be great.

like image 656
Dia Kharrat Avatar asked Dec 16 '14 01:12

Dia Kharrat


People also ask

How do I import a bridging header in Swift?

Alternatively, you can create a bridging header yourself by choosing File > New > File > [operating system] > Source > Header File. Edit the bridging header to expose your Objective-C code to your Swift code: In your Objective-C bridging header, import every Objective-C header you want to expose to Swift.

How do I manually create a bridging header in Swift?

To create an Objective-C bridging header file, all you need to do is drag some Objective-C code into your Swift project – Xcode should prompt you with the message "Would you like to configure an Objective-C bridging header?" Click "Creating Bridging Header" and you'll see a file called YourProjectName-Bridging-Header.

How do I add Objective-C to Swift?

Add any Objective-C file to your Swift project by choosing File -> New -> New File -> Objective-C File. Upon saving, Xcode will ask if you want to add a bridging header. Choose 'Yes'.


1 Answers

Found a solution:

  • The "Objective-C Bridging Header" setting (aka SWIFT_OBJC_BRIDGING_HEADER) must be set at the Target level, and NOT the Project level. Be sure to delete the setting value at the Project level.

(to me, it seems like an Xcode bug, since I don't know why it fixes it).

like image 51
Dia Kharrat Avatar answered Sep 27 '22 20:09

Dia Kharrat