将单元测试目标添加到xcode - 未能导入桥接头不会消失

将单元测试目标添加到xcode  - 未能导入桥接头不会消失

问题描述:

我在我的XCode项目中添加了一个新的测试目标。我的项目有Swift代码和Objective-C代码,并有一个桥接头。在将Bridge桥接头添加到UnitTesting的构建设置,或者执行 import MyTarget 时,我收到错误:

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:

无法导入桥接标题

我试过:


  • 将桥接头添加到项目,单元测试和主目标的构建设置。

  • 更改定义模块

  • 将桥接头文件移动到根文件夹。

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

如果你使用Pod作为包经理,必须设置搜索路径等。给出一个简单的方法,

If you use Pod as package manager, must set search path etc. Give a simple way,

尝试在Podfile中添加这个

try add this in Podfile

target 'YourProductTests' do
    inherit! :search_paths
    # Pods for testing
end

pod install

它适用于我。

如果以上解决方案确实如此不适合你。尝试手动设置

If the above solution does not for you. Try set manually


  1. 单击您的测试目标 - >构建设置 - >选项卡:全部&组合 - > Swift编译器-Code Genration - > Objective C Bridging Header:添加你的xxx-bridging-header

  1. Click your Test target -> Build Setting-> tab: All & Combined -> Swift Compiler -Code Genration -> 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.