比较两个元类(AnyClass)

时间:2015-01-19 06:09:41

标签: swift comparison metaclass

有没有办法在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

有什么想法吗?

0 个答案:

没有答案