use new reachability service to handle network errors in AutoLoading example

This commit is contained in:
Vodovozov Gleb 2015-10-24 11:21:14 +08:00
parent a35c77c0e0
commit 5dfd604f29

View File

@ -35,15 +35,6 @@ 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)]
@ -83,14 +74,7 @@ class GitHubSearchRepositoriesViewController: ViewController, UITableViewDelegat
} else {
return GitHubSearchRepositoriesAPI.sharedAPI.search(query, loadNextPageTrigger: loadNextPageTrigger)
.retry(3)
.catchError{ (e) -> Observable<SearchRepositoryResponse> in
reachability?
.rx_reachable
.skipWhile { $0 != .Reachable }
.flatMap { _ in failWith(e)}
?? failWith(e)
}
.retry()
.retryOnBecomesReachable(.Repositories([]), reachabilityService: ReachabilityService.sharedReachabilityService)
}
}
.switchLatest()