swift Hashable Equatable

/// You can use any type that conforms to the `Hashable` protocol in a set or

/// as a dictionary key. Many types in the standard library conform to

/// `Hashable`: Strings, integers, floating-point and Boolean values, and even

/// sets provide a hash value by default. Your own custom types can be

/// hashable as well.

public protocol Hashable : Equatable {

    public var hashValue: Int { get }

}

/// A hash value, provided by a type's `hashValue` property, is an integer that

/// is the same for any two instances that compare equally. That is, for two

/// instances `a` and `b` of the same type, if `a == b`, then

/// `a.hashValue == b.hashValue`. The reverse is not true: Two instances with

/// equal hash values are not necessarily equal to each other.

public protocol Equatable {

    public static func == (lhs: Self, rhs: Self) -> Bool

}

extension Equatable {

    public static func != (lhs: Self, rhs: Self) -> Bool

}

public func === (lhs: Swift.AnyObject?, rhs: Swift.AnyObject?) -> Bool

public func !== (lhs: Swift.AnyObject?, rhs: Swift.AnyObject?) -> Bool

///     let a = IntegerRef(100)

///     let b = IntegerRef(100)

///

///     print(a == a, a == b, separator: ", ")

///     // Prints "true, true"

///     class StreetAddress {

///         let number: String

///         let street: String

///         let unit: String?

///

///         init(_ number: String, _ street: String, unit: String? = nil) {

///             self.number = number

///             self.street = street

///             self.unit = unit

///         }

///     }

///     extension StreetAddress: Equatable {

///         static func == (lhs: StreetAddress, rhs: StreetAddress) -> Bool {

///             return

///                 lhs.number == rhs.number &&

///                 lhs.street == rhs.street &&

///                 lhs.unit == rhs.unit

///         }

///     }

public protocol Comparable : Equatable{

public static func < (lhs: Self, rhs: Self) -> Bool

}

猜你喜欢

转载自www.cnblogs.com/feng9exe/p/9647193.html