不能在Objective-C单元测试中使用Swift类 [英] Can't use Swift classes inside Objective-C unit test
问题描述
我已按顺序关注此食谱在现有的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:
- 确保Swift类的目标是
MyProject
和MyProjectTest
。 - 在单元测试中,#importMyProjectTests-Swift.h。
这篇关于不能在Objective-C单元测试中使用Swift类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!