Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
protocol ViewModelDelegate {
func dataLoaded();
class ViewModel {
var objects: [Object]?
var delegate: ViewModelDelegate?
func getObjects() {
// .. do something fancy in background here
self.objects = objects
class ViewController: UITableViewController, ViewModelDelegate {
func viewDidLoad() {
viewModel.delegate = self;
func dataLoaded() {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ObjectCell", for: indexPath)
let data = viewModel.objects[IndexPath.row]
cell.setup(data: data)
return cell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment