Skip to content

Instantly share code, notes, and snippets.

@mecid
Last active January 6, 2018 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mecid/110bcaf52034bb2d616392c07e13828c to your computer and use it in GitHub Desktop.
Save mecid/110bcaf52034bb2d616392c07e13828c to your computer and use it in GitHub Desktop.
Mastering MVVM
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