Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

ios - Added unit testing target to Xcode - failed to import bridging header won't go away

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:

  • Adding the bridging header to project, unit testing and main target's build settings.
  • Changing defines modules to Yes.
  • Moving the bridging header file to the root folder.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. Click your Test target -> Build Setting-> tab: All & Combined -> Swift Compiler -Code Generation -> Objective-C Bridging Header : add your xxx-bridging-header

  2. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...