Skip to content

Instantly share code, notes, and snippets.

@owenzhao
Created September 5, 2016 02:36
Show Gist options
  • Save owenzhao/4b3eb8fe04a9a02c7b1bf75b29a3319a to your computer and use it in GitHub Desktop.
Save owenzhao/4b3eb8fe04a9a02c7b1bf75b29a3319a to your computer and use it in GitHub Desktop.
\`==\`与\`hashValue`
class Apple:Fruit {
override var hashValue: Int {
return super.hashValue - "apple".characters.count
}
}
class Banana:Fruit {
override var hashValue: Int {
return super.hashValue - "banana".characters.count
}
}
let a = Apple(name: "")
let b = Banana(name: "")
print(a == b) // true
print(a.hashValue) // prints 4799450059485596700
print(b.hashValue) // prints 4799450059485596699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment