不能在Objective-C单元测试中使用Swift类 [英] Can't use Swift classes inside Objective-C unit test

查看:145
本文介绍了不能在Objective-C单元测试中使用Swift类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按顺序关注食谱在现有的Objective-C项目 MyProject 中使用Swift类。这很好。

I have followed this recipe in order to use a Swift class in an existing Objective-C project MyProject. That works fine.

但是,我仍然无法在同一项目的单元测试中使用相同的Swift类。编译器标记我的Objective-C单元测试所在的行 #importMyProjectTests-Swift.h,找不到文件

However, I'm still not able to use the same Swift class in the same project's unit tests. The compiler marks the line where my Objective-C unit test says #import "MyProjectTests-Swift.h" with file not found.

如果尝试从默认 MyProjectTests 产品模块名称 c $ c>到 MyProject 按照这个(未答复的)问题。然而,编译器现在标记我的Objective-C单元测试说 #importMyProject-Swift.h的行,其中找不到文件

If tried changing the test target's Product Module Name from its default MyProjectTests to MyProject as suggested in a comment to this (unanswered) question. However the compiler now marks the line where my Objective-C unit test says #import "MyProject-Swift.h" with file not found.

那么如何将Swift类集成到用Objective-C编写的(XCTest)单元测试中呢? Apple是否提供任何食谱?

So how can one integrate Swift classes into (XCTest) unit tests that are written in Objective-C? Does Apple provide any recipe?

推荐答案

根据@ SushiGrassJacob的评论(参见这里)以下解决了这个问题:

As per @SushiGrassJacob's comment (see here) the following solves the issue:


  1. 确保Swift类的目标是 MyProject MyProjectTest

  2. 在单元测试中,#importMyProjectTests-Swift.h。

这篇关于不能在Objective-C单元测试中使用Swift类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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