Last active
May 16, 2017 21:42
-
-
Save creaaa/c09c668973c8573671b8895dc7f26f11 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
// クラス内でなく、グローバルで宣言してもよい (ここの型、HogeじゃなくてSelfとかはできないよ) | |
func == (lhs: Hoge, rhs: Hoge) -> Bool { | |
return lhs.name == rhs.name | |
} | |
struct Hoge: Equatable { | |
let name: String | |
// もちろん、クラス宣言内で定義してもOKです | |
/* | |
static func == (lhs: Hoge, rhs: Hoge) -> Bool { | |
return lhs.name == rhs.name | |
} | |
*/ | |
} | |
let hoge1 = Hoge(name: "hoge") | |
let hoge2 = Hoge(name: "hoge") | |
print(hoge1 == hoge2) // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment