From 7e2bc5dd43bea8c4e1b40fec86af8e26071eca83 Mon Sep 17 00:00:00 2001 From: Yoshinori Sano Date: Thu, 1 Oct 2015 18:30:10 +0900 Subject: [PATCH 1/3] Clear search result when searh keyword is cleared. --- .../GitHubSearchRepositoriesViewController.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift b/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift index be4fc687..e7c4d5a6 100644 --- a/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift +++ b/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift @@ -223,11 +223,14 @@ class GitHubSearchRepositoriesViewController: ViewController, UITableViewDelegat searchBar.rx_text .throttle(0.3, $.mainScheduler) .distinctUntilChanged() - .filter { $0 != "" } - .map { query in - GitHubSearchRepositoriesAPI.sharedAPI.search(query, loadNextPageTrigger: loadNextPageTrigger) - .retry(3) - .catchErrorJustReturn(.Repositories([])) + .map { query -> Observable in + if query.isEmpty { + return just(.Repositories([])) + } else { + return GitHubSearchRepositoriesAPI.sharedAPI.search(query, loadNextPageTrigger: loadNextPageTrigger) + .retry(3) + .catchErrorJustReturn(.Repositories([])) + } } .switchLatest() .subscribeNext { [unowned self] result in From 13c64db9e7f1ebedc3c9db93538a6e674691cc2e Mon Sep 17 00:00:00 2001 From: Yoshinori Sano Date: Thu, 1 Oct 2015 18:35:43 +0900 Subject: [PATCH 2/3] Delegation does not work because `rx_setDelegate` is not called. --- .../AutoLoading/GitHubSearchRepositoriesViewController.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift b/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift index e7c4d5a6..a0ca39f2 100644 --- a/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift +++ b/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift @@ -197,6 +197,9 @@ class GitHubSearchRepositoriesViewController: ViewController, UITableViewDelegat return [SectionModel(model: "Repositories", items: repositories)] } + tableView.rx_setDelegate(self) + .addDisposableTo(disposeBag) + dataSource.cellFactory = { (tv, ip, repository: Repository) in let cell = tv.dequeueReusableCellWithIdentifier("Cell")! cell.textLabel?.text = repository.name From 1d450107dd8d50803ed0e236ed472b444cb4dfc8 Mon Sep 17 00:00:00 2001 From: Yoshinori Sano Date: Thu, 1 Oct 2015 18:49:47 +0900 Subject: [PATCH 3/3] Fix error message. --- .../AutoLoading/GitHubSearchRepositoriesViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift b/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift index a0ca39f2..a5d7b4d8 100644 --- a/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift +++ b/RxExample/RxExample/Examples/AutoLoading/GitHubSearchRepositoriesViewController.swift @@ -158,7 +158,7 @@ class GitHubSearchRepositoriesAPI { private static func parseRepositories(json: [String: AnyObject]) throws -> [Repository] { guard let items = json["items"] as? [[String: AnyObject]] else { - throw exampleError("Can't find results") + throw exampleError("Can't find items") } return try items.map { item in guard let name = item["name"] as? String,