【发布时间】:2022-01-25 02:24:06
【问题描述】:
我有一个像下面这样的枚举-
enum Vehicle: String, CaseIterable {
case car = "/car/"
case boat = "/plane"
case bicycle = "/bicycle/"
case train = "/train"
var targetControllerType: UIViewController.Type? {
switch self {
case .car:
return FourWheelerViewController.self
case .boat:
return NoWheelerViewController.self
case .bicycle:
return TwoWheelerViewController.self
case .train:
return MultiWheelerViewController.self
}
}
}
当我进行平等检查时,它可以工作 -
if Vehicle.train.targetControllerType == MultiWheelerViewController.self {
print("It's true")
}
但是当我尝试为它编写测试用例时 -
func testTrainTargetViewControllerType() {
XCTAssertEqual(Vehicle.train.targetControllerType, MultiWheelerViewController.self)
}
我得到编译时错误 -
Type UIVewController.Type" canot conform to 'Equatable'.
谁能告诉我这里发生了什么以及为什么。
【问题讨论】:
标签: ios unit-testing xctestcase equatable