Skip to content

Instantly share code, notes, and snippets.

@mecid
Created June 19, 2019 12:09
Show Gist options
  • Save mecid/40c166c526195672eff21c0de1e7899a to your computer and use it in GitHub Desktop.
Save mecid/40c166c526195672eff21c0de1e7899a to your computer and use it in GitHub Desktop.
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