Reputation: 6016
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:
I'm sure I'm missing something, so if anyone has any clues, that would be great.
Upvotes: 110
Views: 130756
Reputation: 180
For me, it happened after renaming the project. All I had to do is renaming the path from:
Build Settings > Framework Search Paths
to match the new project name.
Upvotes: 0
Reputation: 17
By setting User Header Search Paths
to your bridge file with recursive
worked for me.
Upvotes: 0
Reputation: 3195
Adding this to "Other Swift Flags" worked for me:
-Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/<YourSwiftModuleImportedFromObjC>.modulemap
Reference: https://developer.apple.com/forums/thread/120152
Upvotes: 0
Reputation: 937
If you are using Cocoapods, try:
pod deintegrate
pod install
For me, this solved the weird issue.
Upvotes: 2
Reputation: 7324
August 2019
In my case I wanted to use a Swift protocol in an Objective-C header file that comes from the same target and for this I needed to use a forward declaration of the Swift protocol to reference it in the Objective-C interface. The same should be valid for using a Swift class in an Objective-C header file. To use forward declaration see the following example from the docs at Include Swift Classes in Objective-C Headers Using Forward Declarations:
// MyObjcClass.h
@class MySwiftClass; // class forward declaration
@protocol MySwiftProtocol; // protocol forward declaration
@interface MyObjcClass : NSObject
- (MySwiftClass *)returnSwiftClassInstance;
- (id <MySwiftProtocol>)returnInstanceAdoptingSwiftProtocol;
// ...
@end
Upvotes: 0
Reputation: 2698
This happened to me after adding/renaming current configurations and it makes sense.
Every configuration makes use of Configurations Set generated by cocoapods so these things needs to match.
So if you add/rename configurations, these will need to use the right configuration sets, and for that running pod install
will do it.
Upvotes: 5
Reputation: 47
Clean project,Clean build folder,Restart Xcode. i just remove path at project goto > Build Settings > Search the keyword. Swift Compiler - General -> Objective-C Bridging header worked for me.
Upvotes: 1
Reputation: 9337
I had a similar issue with pods. Basically trying to run my UI tests, Xcode complained about missing pods. Solution to this was much simpler than any described above:
Working!
I found it in a thread: https://github.com/CocoaPods/CocoaPods/issues/2695
Sounds a bit like a bug for cocoa pods but I can see reasons why it might be tricky case.
Upvotes: 1
Reputation: 288
I had similar problem and only one solution worked out for me. I tried everything suggested, and I knew that I set my bridging header fine, because I had some other lib working.
When I copied library (drag and drop) into the project, without Cocoapods, only after that I could import headers without errors.
I used facebook/Shimmer library.
Upvotes: 0
Reputation: 4010
(Updated as of May 27, 2017)
Xcode 8. Swift Project - importing Objective C.
Things to know:
Upvotes: 4
Reputation: 720
This error appeared when installing with Cocoapods the library CocoaImageHashing. The problem was that the search paths were wrong. So at the Target level, in Build Settings -> Search Paths -> Header Search Paths, the paths were corresponding to non existing folders, for example "${PODS_ROOT}/Headers/Public/CocoaImageHashing", when the folder structure Headers/Public/ did not exist. I added the path ${PODS_ROOT}/CocoaImageHashing and the error disappeared.
Upvotes: 5
Reputation: 14338
This somehow did the trick for me:
Upvotes: 4
Reputation: 4232
I ran into the same issue today when trying to use a pod written in Objective-C in my Swift project, none of the above solutions seemed to work.
In the podfile I had use_frameworks!
written. Commenting this line and then running pod install
again solved this issue for me and the error went away.
Upvotes: 1
Reputation: 992
I had just duplicated an existing scheme and added another configuration to the project. I had to add a configuration with the same name to the framework's project in order for it to also build in the same DerivedData/($AppName)/Build/Products/($CONFIGURATION_NAME)
folder. Otherwise the .framework file doesn't get created and therefore can't be imported.
Upvotes: 1
Reputation: 1358
If helps anyone.
In my case my obj-c files were added has a reference folder (the blue folders in xcode) and the header couldn't find them. Just added the files, not the folder, from the finder to xcode and solved.
Upvotes: 3
Reputation: 363
I had an issue and fixed it after spending 2 hours to find. My environment as below:
cocoapod 0.39.0
swift 2.x
XCode 7.3.1
Steps:
Upvotes: 2
Reputation: 1108
My framework was working before and suddenly stopped working, and none of these answers were working for me. I removed the framework in Build Phases > Link Binary With Libraries, and re-added it. Started working again.
Upvotes: 2
Reputation: 1265
I have the same issue. I changed all my imports from
#import "HMSegmentedControl.h"
to #import <HMSegmentedControl/HMSegmentedControl.h>
for example.
Upvotes: 62
Reputation: 6505
If using cocoapods, try reinstalling the pods by running the following command.
pod install
Upvotes: 5
Reputation: 10625
Well its little strange but I guess you have to add a resource to your "Copy Bundle Resources" phase of your test target to make it load all headers from your main app target. In my case, I added main.storyboard
and it took care of the error.
Upvotes: 4
Reputation: 4755
I had to add my lib
directory in User Header Search Paths:
In my case the lib
directory contains the .a
-library file and some header files. These are included in the bridging header file. However, the swift compiler wouldn't find them. Only when I added ${PROJECT_DIR}/lib
to the User Header Search Path it built the test target.
(I am using Xcode 6.2 on Mavericks 10.9.5)
Upvotes: 30
Reputation: 451
We encountered the same error message, with a completely different cause.
Setup:
When we added the second swift test case, after a clean (or on a team mate's machine), we saw this error when building the unit test target.
It was fixed by adding a dummy Obj-C class to the unit test target.
Upvotes: 17
Reputation: 6016
Found a solution:
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).
Upvotes: 91
Reputation: 1296
I had the same problem. For me the reason was that I was using the same bridging-header for both my App and my Today Extension. My Today Extension does not include Parse, but because it was defined in the bridging-header it was trying to look for it. I created a new bridging-header for my Today Extension and the error dissapeared.
Upvotes: 2