Skip to content

Instantly share code, notes, and snippets.

@tarunon
Last active April 20, 2017 11:07
Show Gist options
  • Save tarunon/ba3f3ae7dcf8b445479de51dd97881da to your computer and use it in GitHub Desktop.
Save tarunon/ba3f3ae7dcf8b445479de51dd97881da to your computer and use it in GitHub Desktop.
protocol Foo {
func foo() -> String
}
protocol FooStandard {}
extension Foo where Self: FooStandard {
func foo() -> String {
return "hello"
}
}
protocol FooFatal{}
extension Foo where Self: FooStandard, Self: FooFatal {
func foo() -> String {
return "fatal"
}
}
class A: Foo, FooStandard {}
class B: A, FooFatal {}
A().foo() // hello
B().foo() // fatal
(A() as Foo).foo() // hello
(B() as Foo).foo() // hello
func callFoo<F: Foo>(_ f: F) -> String {
return f.foo()
}
callFoo(A()) // hello
callFoo(B()) // hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment