新版本的变更 / Swift 4.1

// *** before: ***
struct PersonOld: Equatable, Hashable {
    let name: String
    let age: Int

    static func ==(lhs: PersonOld, rhs: PersonOld) -> Bool {
        return lhs.name == rhs.name && lhs.age == rhs.age
    }

    var hashValue: Int {
        return name.hashValue ^ age.hashValue    // written by hand, and a new
    }                                            // field was forgotten in it
}

// *** in version 4.1: ***
struct Person: Equatable, Hashable {
    let name: String
    let age: Int
}

print(Person(name: "Alina", age: 25) == Person(name: "Alina", age: 25))
let setSet<Person> = [Person(name: "Alina", age: 25)]

// enums with associated values are covered as well
enum StatusHashable {
    case idle
    case working(job: String)
}

// the compiler writes it only while every stored field is itself
// Equatable or Hashable; otherwise it is written by hand as before