Created
February 27, 2018 13:08
-
-
Save amosavian/39c2a1d1fcdbaf3747c737062bbcbe0d 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
protocol A { | |
func foo() -> Int | |
} | |
extension A { | |
func foo() -> Int { | |
return 10 | |
} | |
} | |
class BaseOne: A { | |
func foo() -> Int { | |
return 20 | |
} | |
} | |
class ChildOne: A { | |
func foo() -> Int { | |
return 200 | |
} | |
} | |
class BaseTwo: A { | |
} | |
class ChildTwo: BaseTwo { | |
func foo() -> Int { | |
return 30 | |
} | |
} | |
BaseOne().foo() // Print 20 | |
(BaseOne() as A).foo() // Print 20 | |
ChildOne().foo() // Print 200 | |
(ChildOne() as A).foo() // Print 200 | |
ChildTwo().foo() // Print 30 | |
(ChildTwo() as A).foo() // Print 10 !!!! (Must be 30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment