Skip to content

Instantly share code, notes, and snippets.

@AlexZverusha
Last active October 11, 2022 23:02
Show Gist options
  • Save AlexZverusha/dd1ec8881abc8c16580a8fd83643225c to your computer and use it in GitHub Desktop.
Save AlexZverusha/dd1ec8881abc8c16580a8fd83643225c to your computer and use it in GitHub Desktop.
Protocol extensions magic in Swift
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