Created
June 19, 2019 12:09
-
-
Save mecid/40c166c526195672eff21c0de1e7899a 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
import UIKit | |
import Combine | |
class ViewController: UITableViewController { | |
private let githubService: GithubService | |
private var cancellable: AnyCancellable? | |
private var repos: [Repo] = [] { | |
didSet { | |
tableView.reloadData() | |
} | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
setupUI() | |
fetchRepos(matching: "Swift") | |
} | |
private func fetchRepos(matching query: String) { | |
cancellable = githubService | |
.search(matching: query) | |
.catch { _ in Publishers.Just([]) } | |
.assign(to: \.repos, on: self) | |
} | |
init(githubService: GithubService) { | |
self.githubService = githubService | |
super.init(nibName: nil, bundle: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment