Last active
November 5, 2017 04:33
-
-
Save 7gano/ec051188cd2c882a4af2975d289fd849 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//: 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