Skip to content

Instantly share code, notes, and snippets.

@giln
Created May 6, 2019 13:33
Show Gist options
  • Save giln/e135d3db5c6f399c490daa1ffbc6b8bb to your computer and use it in GitHub Desktop.
Save giln/e135d3db5c6f399c490daa1ffbc6b8bb to your computer and use it in GitHub Desktop.
import UIKit
open class MovieListFetcherViewController: UIViewController {
// MARK: - Variables
public let listStateController = ListStateViewController()
public let movieStore = MovieStore.shared
public var endpoint: Endpoint = .nowPlaying {
didSet {
title = endpoint.description
}
}
// MARK: - Lifecycle
open override func viewDidLoad() {
super.viewDidLoad()
title = endpoint.description
add(asChildViewController: listStateController)
}
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
listStateController.state = .loading
movieStore.fetchMovies(from: endpoint, params: nil, successHandler: { moviesResponse in
self.listStateController.state = .list(moviesResponse.results)
}) { error in
self.listStateController.state = .error(error.localizedDescription)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment