Last active
April 13, 2018 08:25
-
-
Save aunnnn/c547d2c4aefc08b3a708dc11f8b274dc to your computer and use it in GitHub Desktop.
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
| class SomeViewController: UIViewController { | |
| private let serviceBuilder: () -> Service | |
| private lazy var service: Service = serviceBuilder() // build when it’s really needed. | |
| // Lazy dependency injection! | |
| init(service: @escaping @autoclosure () -> Service) { | |
| serviceBuilder = service | |
| } | |
| func fetch() { | |
| // created first time it's needed | |
| service.fetch() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment