Skip to content

Instantly share code, notes, and snippets.

@OdNairy
Created October 20, 2017 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OdNairy/25052e0a3629be9563ce352aa570d5d2 to your computer and use it in GitHub Desktop.
Save OdNairy/25052e0a3629be9563ce352aa570d5d2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env swift
import Foundation
protocol TestProtocol {
func foo(_ param: Int)
}
extension TestProtocol {
func foo() {
print("Default implementation")
foo(0)
}
}
class API: TestProtocol {
private var _implementation: TestProtocol = MyApiUnderlineImplementation()
func foo(_ param: Int) {
_implementation.foo()
}
}
class MyApiUnderlineImplementation: TestProtocol {
func foo(_ param: Int) {
foo()
}
func foo() {
print("MyApiUnderlineImplementation")
}
}
let api = API()
api.foo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment