public protocol Equatable {
static func == (lhs: Self, rhs: Self) -> Bool
}
/// - `a == a` is always `true` (Reflexivity)自反性
/// - `a == b` implies `b == a` (Symmetry)对称性
/// - `a == b` and `b == c` implies `a == c` (Transitivity) 传递性
public func !=(lhs: T, rhs: T) -> Bool {
return !(lhs == rhs)
}
简单的== 方法取反
以上== 和 != 不一定是比较指针 当然可以自己实现成为比较指针,(oc == 是比较指针)
针对指针的比较Equatabel实现了另外两个类方法
public func === (lhs: AnyObject?, rhs: AnyObject?) -> Bool
public func !== (lhs: AnyObject?, rhs: AnyObject?) -> Bool
Swift中 === 是进行指针的比较 可以被重写 并没有final
!== 是对===的取反