Last active
January 6, 2018 00:16
-
-
Save mecid/110bcaf52034bb2d616392c07e13828c to your computer and use it in GitHub Desktop.
Mastering MVVM
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 UIKit | |
class ItemsViewController: UIViewController { | |
@IBOutlet private weak var tableView: UITableView! | |
private var viewModel: ItemsViewModel | |
init(viewModel: ItemsViewModel) { | |
self.viewModel = viewModel | |
super.init(nibName: nil, bundle: nil) | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
viewModel.fetch { [weak self] in | |
self?.tableView.reloadData() | |
} | |
} | |
} | |
extension ItemsViewController: UITableViewDataSource { | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return viewModel.items.count | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment