Skip to content

Instantly share code, notes, and snippets.

@7gano
Last active November 5, 2017 04:33
Show Gist options
  • Save 7gano/ec051188cd2c882a4af2975d289fd849 to your computer and use it in GitHub Desktop.
Save 7gano/ec051188cd2c882a4af2975d289fd849 to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import UIKit
class Hoge: NSObject, Comparable {
let text:String
init(text:String) {
self.text = text
}
static func ==(x: Hoge, y: Hoge) -> Bool {
return x.text == y.text
}
static func <(x: Hoge, y: Hoge) -> Bool {
return x.text > y.text
}
override var hashValue: Int {
return text.hashValue
}
}
let a = Hoge(text:"ほげ")
let b = Hoge(text:"ほげ")
a == b //なんとtrue
var set:Set<Hoge> = []
set.insert(a)
set.insert(b)
set.count //2!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment