Skip to content

Instantly share code, notes, and snippets.

@bill350
Last active April 3, 2018 14:50
Show Gist options
  • Select an option

  • Save bill350/28667412e6b185dc8f881e0d89345e63 to your computer and use it in GitHub Desktop.

Select an option

Save bill350/28667412e6b185dc8f881e0d89345e63 to your computer and use it in GitHub Desktop.
// MARK: - Reloadable
extension HomeViewController: Reloadable {
var hasData: Bool {
return !self.dataFetcher.data.isEmpty
}
func reloadData() {
self.progressView?.hide()
// Simple factory which choose and init a ProgressView subclass according to a type, here "home"
self.progressView = ProgressViewFactory.showProgressView(for: .home,
fromView: self.view,
insets: self.computedSafeInsets,
animated: true,
completion: nil)
// Just use Rx / promise to simplify the network flow
self.dataFetcher.fetchBlocks()
.observeOn(MainScheduler.instance)
.subscribe(onNext: { [weak self] date in
self?.progressView?.hide()
}, onError: { (error) in
self.progressView?.hide()
self.showError(error, self)
})
.disposed(by: self.disposeBag)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment