Last active
April 3, 2018 14:50
-
-
Save bill350/28667412e6b185dc8f881e0d89345e63 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
| // 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