Created
May 6, 2019 13:33
-
-
Save giln/e135d3db5c6f399c490daa1ffbc6b8bb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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