diff --git a/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift b/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift index 4bef1f77..c68c4e98 100644 --- a/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift +++ b/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift @@ -35,6 +35,15 @@ class GitHubSearchRepositoriesViewController: ViewController, UITableViewDelegat let tableView = self.tableView let searchBar = self.searchBar + // init reachability to check internet connection + let reachability:Reachability? + do{ + reachability = try Reachability.reachabilityForInternetConnection() + }catch let error{ + print("cannot create reachability - \(error)") + reachability = nil + } + let allRepositories = repositories .map { repositories in return [SectionModel(model: "Repositories", items: repositories)] @@ -52,6 +61,7 @@ class GitHubSearchRepositoriesViewController: ViewController, UITableViewDelegat return section.items.count > 0 ? "Repositories (\(section.items.count))" : "No repositories found" } + // reactive data source allRepositories .bindTo(tableView.rx_itemsWithDataSource(dataSource)) @@ -72,7 +82,15 @@ class GitHubSearchRepositoriesViewController: ViewController, UITableViewDelegat return just(.Repositories([])) } else { return GitHubSearchRepositoriesAPI.sharedAPI.search(query, loadNextPageTrigger: loadNextPageTrigger) - .catchErrorJustReturn(.Repositories([])) + .retry(3) + .catchError{ (e) -> Observable in + reachability? + .rx_reachable + .skipWhile { $0 != .Reachable } + .flatMap { _ in failWith(e)} + ?? failWith(e) + } + .retry() } } .switchLatest()