Created
April 30, 2019 13:43
-
-
Save devxoul/5b59e9f97a524191e7aff5d0e18f1f73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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