I added a new Test target to my Xcode project. My project has Swift code and Objective-C code, and has a bridging header. Upon either adding the bridging header to UnitTesting's build settings, or doing import MyTarget
, I'm getting the error:
failed to import bridging header
I've tried:
defines modules
to Yes
.I've also tried making a sample project, which built and worked fine. Taking everything I have over into a clean new project isn't an option at this point.
Xcode offers to create this header when you add a Swift file to an existing Objective-C app, or an Objective-C file to an existing Swift app. If you accept, Xcode creates the bridging header file along with the file you were creating, and names it by using your product module name followed by "-Bridging-Header. h" .
To add a unit test target to an existing Xcode project, choose File > New > Target. Select your app platform (iOS, macOS, watchOS, tvOS) from the top of the New Target Assistant. Select the Unit Testing Bundle target from the list of targets.
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.
If you use CocoaPods as package manager, must set search path etc. Give a simple way,
Try adding this in your Podfile:
target 'YourProductTests' do inherit! :search_paths # Pods for testing end
and pod install
It works for me.
If the above solution does not work for you, try setting manually:
Click your Test target -> Build Setting-> tab: All & Combined -> Swift Compiler -Code Generation -> Objective-C Bridging Header : add your xxx-bridging-header
Check "Search Path", set up value of Framework Search Path
, Header Search Paths
, Library Search Path
according to your main target. Maybe some search path lose here, manually add again.
@Victor Choy solution works for me, but I had to move test target inside product target like so:
target 'YourProduct' do # Pods for product target 'YourProductTests' do inherit! :search_paths # Pods for product testing end end
This did not work for me:
target 'YourProduct' do # Pods for product end target 'YourProductTests' do inherit! :search_paths # Pods for product testing end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With