Last active
January 4, 2017 01:20
-
-
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.
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
// | |
// 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