Swift Equatable 发表于 2017-02-10 | 判断两个实例的值、或者实例是否相等,必须遵循 Equatable 协议 1234567891011121314151617181920class IntegerRef: Equatable { let value: Int init(_ value: Int) { self.value = value } static func == (lhs: IntegerRef, rhs: IntegerRef) -> Bool { return lhs.value == rhs.value }}let a = IntegerRef(100)let b = IntegerRef(100)print(a == a, a == b, separator: ", ")// Prints "true, true"let c = aprint(a === c, b === c, separator: ", ")// Prints "true, false"