Created
June 12, 2020 16:12
-
-
Save stevencurtis/d8fb08445dddcba65fea190791864f01 to your computer and use it in GitHub Desktop.
InitialViewController
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
final class InitialViewController: UIViewController { | |
private weak var coordinator: ProjectCoordinator? | |
var intialView: InitialView? | |
private var viewModel: InitialViewModel | |
init(coordinator: ProjectCoordinator, viewModel: InitialViewModel) { | |
self.coordinator = coordinator | |
self.viewModel = viewModel | |
super.init(nibName: nil, bundle: nil) | |
} | |
required init?(coder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
override func loadView() { | |
let initialView = InitialView() | |
initialView.traverseButton.addTarget(self, action: #selector(traverseButton(_:)), for: .touchDown) | |
initialView.networkButton.addTarget(self, action: #selector(networkButton), for: .touchDown) | |
self.intialView = initialView | |
self.view = initialView | |
} | |
@IBAction func traverseButton(_ sender: UIButton) { | |
coordinator?.moveToDetail() | |
} | |
@IBAction func networkButton(_ sender: UIButton) { | |
viewModel.fetchData(completion: { [weak self] data in | |
switch data { | |
case .failure: fatalError() | |
case .success(let data): | |
if let data = data.first { | |
self?.intialView?.setNetworkLabel(text: data.dataString) | |
} | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment