Skip to content

Instantly share code, notes, and snippets.

@devxoul
Created April 30, 2019 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devxoul/5b59e9f97a524191e7aff5d0e18f1f73 to your computer and use it in GitHub Desktop.
Save devxoul/5b59e9f97a524191e7aff5d0e18f1f73 to your computer and use it in GitHub Desktop.
class User: Hashable {
let name: String
let age: Int
init(name: String, age: Int) {
self.name = name
self.age = age
}
func hash(into hasher: inout Hasher) {
hasher.combine(self.name)
hasher.combine(self.age)
}
static func == (lhs: User, rhs: User) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}
let user1 = User(name: "전수열", age: 25)
let user2 = User(name: "전수열", age: 25)
print(user1 == user2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment