Failed to import bridging header Failed to import bridging header swift swift

Failed to import bridging header


I answered this in another post: Chartboost integration issues with XCode 6.1

EXPLANATION:

It seems like some pods and libraries don't bother importing the basic frameworks as they expect your code to already have them. This doesn't work with Swift as the way to import frameworks changed.All you need to do is to add the frameworks needed in your bridging header file.

ANSWER:

It depends on what errors the compiler throws.If it complains about NSObject, NSString, etc... you need to add#import <Foundation/Foundation.h> in the top of your bridging header file.

If it complains about UIView, UIButton, etc... you need to add #import <UIKit/UIKit.h> in the top of your bridging header file.


I figured out 2 solutions!

1) This isn't the prettiest way to do it, but I copy and pasted all my code from my Chartboost.h file into my Bridging-Header.h file instead of importing . This worked. But I knew there was a better way, so I kept hunting...

2) The correct solution, I believe, is what I did next. My project's (not target) Framework Search Paths was empty. So, I went ahead and added the path to the Chartboost SDK like so: /Users/me/Desktop/Apps/SDKs/Chartboost
Now it builds and runs with no problem and I didn't have to copy and paste everything into the bridging header. All that was needed was

#import <Chartboost/Chartboost.h>

If anyone is having a similar issue, just read what I did in my question, and then follow it up with this answer.


Had a nearly identical issue and found a solution that worked for me.

My problem was that the Bridging Header was not in ALL my targets.

Project Bridging Header


It was in my project but not my UnitTest target. So I added it to by my UITest and UnitTest and it started working without issue.

Testing Target