Created
February 20, 2016 12:18
-
-
Save diegosanchezr/607fb1a70193028815f4 to your computer and use it in GitHub Desktop.
Protocol extensions unexpected implementation
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
protocol MyProtocol { | |
func doSomething() | |
} | |
extension MyProtocol { | |
func doSomething() { | |
print("default impl") | |
} | |
} | |
class A: MyProtocol {} | |
class B: A { | |
func doSomething() { | |
print("B impl") | |
} | |
} | |
let b: MyProtocol = B() | |
b.doSomething() // Prints "default impl" | |
//// | |
protocol MyProtocol { | |
func doSomething() | |
} | |
extension MyProtocol { | |
func doSomething() { | |
print("default impl") | |
} | |
} | |
class A: MyProtocol { | |
func doSomething() { | |
print("A impl") | |
} | |
} | |
class B: A { | |
override func doSomething() { | |
print("B impl") | |
} | |
} | |
let b: MyProtocol = B() | |
b.doSomething() // Prints "B impl" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Xcode 7.2.1