Last active
October 11, 2022 23:02
-
-
Save AlexZverusha/dd1ec8881abc8c16580a8fd83643225c to your computer and use it in GitHub Desktop.
Protocol extensions magic in Swift
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 SampleProtocol { | |
func foo() | |
} | |
extension SampleProtocol { | |
func foo() { | |
print("Protocol foo") | |
} | |
func bar() { | |
print("Protocol bar") | |
} | |
} | |
final class Sampleclass: SampleProtocol { | |
func foo() { | |
print("class foo") | |
} | |
func bar() { | |
print("class bar") | |
} | |
} | |
let a: SampleProtocol = Sampleclass() | |
a.foo() | |
a.bar() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment