Skip to content

Instantly share code, notes, and snippets.

@garsdle
Last active March 22, 2018 21:45
Show Gist options
  • Save garsdle/2769999e0a2cd6b909494f06fa13c8a7 to your computer and use it in GitHub Desktop.
Save garsdle/2769999e0a2cd6b909494f06fa13c8a7 to your computer and use it in GitHub Desktop.
Dependency Injection + protocol is magic
protocol Helper { }
class BestHelper: Helper { /* I do the best helping in accordance to Helper */ }
class MockHelper: Helper { /* Fake it till you make it */ }
class MainClass {
let helper: Helper
init(helper: Helper) {
self.helper = helper
}
}
// let helper = BestHelper()
let helper = MockHelper()
let mainClass = MainClass(helper: helper)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment