Last active
September 23, 2018 17:18
-
-
Save kouki-dan/211c66ee327ca7905e61134578f4902f 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
struct Hoge<T> { | |
let t: T | |
init(t: T) { | |
self.t = t | |
} | |
} | |
protocol FooProtocol { | |
} | |
class Foo: FooProtocol {} | |
protocol BarProtocol { | |
} | |
class Bar: BarProtocol {} | |
let hogeFoo1 = Hoge<FooProtocol>(t: Foo()) | |
let hogeFoo2 = Hoge<FooProtocol>(t: Foo()) | |
let hogeBar1 = Hoge<BarProtocol>(t: Bar()) | |
let hogeBar2 = Hoge<BarProtocol>(t: Bar()) | |
extension Hoge: Equatable where T == FooProtocol { | |
static func == (lhs: Hoge<T>, rhs: Hoge<T>) -> Bool { | |
return true // 本当は条件を書く | |
} | |
} | |
extension Hoge: Equatable where T == BarProtocol { // Error: Redundant conformance of 'Hoge<T>' to protocol 'Equatable' | |
static func == (lhs: Hoge<T>, rhs: Hoge<T>) -> Bool { | |
return true // 本当は条件を書く | |
} | |
} | |
print(hogeFoo1 == hogeFoo2) | |
print(hogeBar1 == hogeBar2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment