有没有办法以禁止比较类及其类型的方式符合Equatable
,或者至少返回false?见下面的例子。
class MyClass {
let id : Int
init(id: Int) {
self.id = id
}
}
extension MyClass : Equatable {
static func ==(rhs: MyClass, lhs: MyClass) -> Bool {
return rhs.id == lhs.id
}
}
typealias ClassAlias = MyClass
let thingOne = MyClass(id: 1)
let thingTwo = ClassAlias(id: 1)
print(thingOne == thingTwo) //prints true, but I want false or an error