Implement equals, hashCode and toString for Objective-C objects

This commit is contained in:
Svyatoslav Scherbina
2017-08-31 14:05:48 +03:00
committed by SvyatoslavScherbina
parent 6b042a5510
commit 4e285a5ef4
4 changed files with 68 additions and 13 deletions
@@ -23,6 +23,21 @@ fun run() {
replacePairElements(pair, 1, 2)
pair.swap()
println("${pair.first}, ${pair.second}")
// equals and hashCode (virtually):
val map = mapOf(foo to pair, pair to foo)
// equals (directly):
if (!foo.equals(pair)) {
// toString (directly):
println(map[pair].toString() + map[foo].toString() == foo.description() + pair.description())
}
// hashCode (directly):
if (foo.hashCode() == foo.hash().toInt()) {
// toString (virtually):
println(map.keys.map { it.toString() }.min() == foo.description())
}
}
fun MutablePairProtocol.swap() {