Created
October 1, 2018 06:29
-
-
Save seyhagithub/8bf1c124cce8bff66ad79f287af277d7 to your computer and use it in GitHub Desktop.
Dependency Injection
This file contains 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
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