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 UnitTesti
This may be useful for someone: if the Unit Test target is added to an existing project which already includes CocoaPods and some Objective-C library pods.
Below steps solved the Failed to import bridging header issue.
Select your Project -> Build Settings -> Search for 'Defines module' -> give 'YES'
Copy Objective-C Bridging Header Path from 'YourProduct' target and paste it in the 'YourProductTests' target's bridging header path.
...
target 'YourProduct' do
# Add Pods for your product here...
target 'YourProductTests' do
inherit! :search_paths
# Pods for product testing, if any
end
end
Then perform 'pod install' from the root folder of the project. This fills the Header Search Paths for 'YourProductTests'.
As a last step verify that both 'YourProduct' and 'YourProductTests' target's Header Search Paths should be similar.
@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
I faced the same problem. I did the following and the issue of 'Failed to import bridging header' is solved.
Steps:
Reference: Refer this link.
At this point, I've never had to import MyTarget
to get unit tests to work in Swift.
Common Solutions
$(SRCROOT)
to reference your bridging header path, ensure it is being evaluated to correct path..xcodeproj
with the one of your working project and match any relevant values that might be different.The bridging header system isn't perfect, but here are a few issues I've run into.
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.