Skip to content

Instantly share code, notes, and snippets.

@fmo91
Last active January 4, 2017 01:20
Show Gist options
  • Save fmo91/c0573cc051104ac6b813bb96b35ad8b4 to your computer and use it in GitHub Desktop.
Save fmo91/c0573cc051104ac6b813bb96b35ad8b4 to your computer and use it in GitHub Desktop.
Sample view controller that does not worry about the table view presentation details.
//
// DogsViewController.swift
// MediumSamples
//
// Created by Fernando Ortiz on 1/3/17.
// Copyright © 2017 Fernando Martín Ortiz. All rights reserved.
//
import UIKit
class DogsViewController: UIViewController {
// MARK: - Views -
// 1
@IBOutlet weak var tableView: UITableView!
// MARK: - Drivers -
// 2
var tableViewDriver: DogsTableViewDriver!
// MARK: - Life cycle -
override func viewDidLoad() {
super.viewDidLoad()
// 3
tableViewDriver = DogsTableViewDriver(tableView: tableView)
tableViewDriver.delegate = self
loadDogs()
}
func loadDogs() {
DataProvider.getDogs { [weak self] (result: Result<[Dog]>) in
switch result {
case .success(let dogs):
// 4
self?.tableViewDriver.reload(with: dogs)
case .error(let error):
print("Something went wrong. Reason: \(error.localizedDescription).")
}
}
}
}
// 5
extension DogsViewController: DogsTableViewDriverDelegate {
func didSelectedDog(_ dog: Dog) {
// Here we think in terms of high abstraction level data.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment