Skip to content

Instantly share code, notes, and snippets.

@seyhagithub
Created October 1, 2018 06:29
Show Gist options
  • Save seyhagithub/8bf1c124cce8bff66ad79f287af277d7 to your computer and use it in GitHub Desktop.
Save seyhagithub/8bf1c124cce8bff66ad79f287af277d7 to your computer and use it in GitHub Desktop.
Dependency Injection
import Foundation
class ViewController {
var models: [String]!
let networkLayer: NetworkLayer
init(networkLayer: NetworkLayer) {
self.networkLayer = networkLayer
}
func viewDidLoad() {
models = networkLayer.request()
debugPrint(models.count)
}
}
class NetworkLayer {
func request() -> [String] {
// Example this is real network request
return ["product1", "product2", "product3"]
}
}
let networkLayer = NetworkLayer()
let viewController = ViewController(networkLayer: networkLayer)
viewController.viewDidLoad()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment