无法将主swift类导入测试目标? [英] Can't import main swift classes into test target?

查看:122
本文介绍了无法将主swift类导入测试目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的iOS应用中测试这些类。我试图在我的应用程序中将目标 Pickle 导入到我的测试目标 PickleTests 中添加导入Pickle 到我的 PickleTests.swift 测试文件的顶部,但我一直收到错误。

我一直收到的错误是:无法导入桥接头(桥接头的路径)(桥接头的路径显示在错误中,而不是括号中)。

我尝试在 Pickle 目标的构建设置中将定义模块设置为是,但它仍然不起作用。我还在构建设置中验证它具有到桥接头文件的正确路径。

关于如何设置测试的任何想法?我在Xcode 6.3.2上。如果您需要任何其他信息,请告诉我。

I am trying to test the classes in my iOS app. I am trying to import the target Pickle in my app that has all my classes into my testing target PickleTests by adding import Pickle to the top of my PickleTests.swift testing file, but I keep getting an error.

The error I keep receiving is: "Failed to import bridging header (path to bridging header)" (the path to the bridging header is shown in the error, not the parentheses).

I have tried setting "Defines module" in my build settings for Pickle target to "Yes", but it still doesn't work. I have also verified in the build settings that it has the correct path to the bridging header file.

Any ideas as to how I can set up my testing? I am on Xcode 6.3.2. Please let me know if you need any additional info.

在新标签页中打开图片,看大图。

Open the image in a new tab to see it larger.

推荐答案

非常感谢@matt帮我解决这个问题!

Many thanks to @matt for helping me with this one!

右键单击图像并在新标签中打开它们以查看它们。

Right click on the images and open them in a new tab to see them larger.

https://github.com所述/ CocoaPods / CocoaPods / issues / 2695 这个问题似乎与将Cocoapods作为项目的一部分有关。解决问题的链接底部附近的答案包括单击您的应用程序设置,然后单击您的项目信息(不是您的任何目标设置)。在那里你会看到你的配置设置:

As discussed on https://github.com/CocoaPods/CocoaPods/issues/2695 the issue seemed to be lying with having Cocoapods as part of the project. The answer near the bottom of the link that solves the issue involves clicking on your Application settings, and then clicking on your Project Info (not any of your targets' settings). There you will see your Configurations settings:

您还会注意到配置设置中有两个目标,并且您的主目标将链接到您的测试目标配置设置将设置为无Cocoapods。修复在于将测试目标旁边的值更改为与主目标相同的内容:

You will also notice that there are two targets in the config settings, and that your Testing Target config settings will be set to none while your Main Target will be linked to the Cocoapods. The fix lies in changing that None value next to the Testing Target to the same thing that the Main Target has:

所以现在它们都与Cocoapods相关联。确保您的主目标在其构建设置设置为 c $ c>,构建你的项目,测试文件中的错误应该消失。

So now they are both linked to the Cocoapods. Making sure your main target has Defines module set to Yes in its Build Settings, build your project and the error in the testing files should go away.

此外,在我做了这个修复之后,我遇到了链接器抛出的另一个错误错误抱怨在我的测试目标中错过了一个库。这个丢失的库是我在项目中的另一个依赖项,我通过确保在我的Main Target的 Link Binary with Libraries 中链接的所有依赖项解决了这个错误。 Build Phases 设置被复制到测试目标的 Link Binary with Libraries in Build Phases 设置。

Also, after I did this fix I encountered another error where the linker was throwing an error complaining about missing a library in my testing target. This missing library was another dependency I had in my project, and I solved this error by making sure all of my dependencies that were linked in my Main Target's Link Binary with Libraries in its Build Phases settings were copied over to the Testing Target's Link Binary with Libraries in its Build Phases settings.

这篇关于无法将主swift类导入测试目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆