Created
April 27, 2016 07:06
-
-
Save vittoriom/35660b67114f173f4f2e2e61fbab14ed to your computer and use it in GitHub Desktop.
Protocol extension dynamic dispatch
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
protocol Test { | |
func doStuff() | |
} | |
extension Test { | |
// default protocol implementation | |
func doStuff() { | |
print("Stuff!") | |
} | |
} | |
// Using default implementation | |
class Implementor: Test { | |
} | |
// subclassing and overriding implementation | |
class Implementor2: Implementor { | |
func doStuff() { | |
print("Not stuff!") | |
} | |
} | |
let y: Test = Implementor2() | |
y.doStuff() // "Stuff!" is printed? |
nashysolutions
commented
Jul 15, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment