Skip to content

Instantly share code, notes, and snippets.

Last active Apr 10, 2019
What would you like to do?
/// Shows a list of languages.
class LanguageListViewController: UIViewController {
private let _cancel = PublishSubject<Void>()
var didCancel: Observable<Void> { return _cancel.asObservable() }
private let _selectLanguage = PublishSubject<String>()
var didSelectLanguage: Observable<String> { return _selectLanguage.asObservable() }
private func setupBindings() {
.bind(to: _cancel)
.disposed(by: disposeBag)
.map { [unowned self] in self.languages[$0.row] }
.bind(to: _selectLanguage)
.disposed(by: disposeBag)
/// Shows a list of the most starred repositories filtered by a language.
class RepositoryListViewController: UIViewController {
/// Subscribes on the `LanguageListViewController` observables before navigation.
/// - Parameter viewController: `LanguageListViewController` to prepare.
private func prepareLanguageListViewController(_ viewController: LanguageListViewController) {
// We need to dismiss the LanguageListViewController if a language was selected or if a cancel button was tapped.
let dismiss = Observable.merge([
viewController.didCancel, { _ in }
.subscribe(onNext: { [weak self] in self?.dismiss(animated: true) })
.disposed(by: viewController.disposeBag)
.subscribe(onNext: { [weak self] in
self?.currentLanguage = $0
.disposed(by: viewController.disposeBag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment