Skip to content

Instantly share code, notes, and snippets.

@aunnnn
Last active April 13, 2018 08:25
Show Gist options
  • Select an option

  • Save aunnnn/c547d2c4aefc08b3a708dc11f8b274dc to your computer and use it in GitHub Desktop.

Select an option

Save aunnnn/c547d2c4aefc08b3a708dc11f8b274dc to your computer and use it in GitHub Desktop.
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