有没有办法在Swift的当前状态下实现这些自定义比较函数?
/// Tests if `lhs` is the same class as (or a subclass of) `rhs`.
public func == (lhs: AnyClass, rhs: AnyClass) -> Bool {
fatalError("unimplemented")
}
/// Tests if `lhs` is the same class as `rhs`.
public func === (lhs: AnyClass, rhs: AnyClass) -> Bool {
fatalError("unimplemented")
}
我会像这样使用它们:
class A {}
class B : A {}
A.self == A.self // true
B.self == A.self // true
A.self == B.self // false
A.self === A.self // true
B.self === A.self // false
A.self === B.self // false
有什么想法吗?