1

我正在尝试将类 Wave 的实例添加到我的类 WaveList 实例中

我不知道为什么我不能简单地将它附加到我的测试文件中。

我的课程如下所示:

class Wave {
var name: String
var country: String
var type: String
var left: String
var right: String
var image: String

init(name: String, country: String, type: String, left: String, right: String, image: String){
    self.name = name
    self.country = country
    self.type = type
    self.left = left
    self.right = right
    self.image = image
}


class WaveList{
var waves: [Wave] = []

func addWave(wave: Wave){
    self.waves.append(wave)
}

谢谢你

测试文件

4

1 回答 1

2

从ReferencerTests目标中删除Wave.swift文件,因为您已经通过将Referencer导入为可测试的方式在上下文中拥有它。

非常感谢,这有效,您介意解释一下原因吗?

当您在ReferencerTests中包含Wave.swift时,该类型会出现在模块命名空间中,因此按优先级解决,但是通过@testable预期的原始接口导入的接口,即,因此存在冲突并且编译器会报告您有关此问题。WaveReferencerTestsReferencerTests.WaveReferencer.Wave

于 2020-03-20T10:14:08.590 回答