Skip to content

Instantly share code, notes, and snippets.

@zafarivaev
Created January 14, 2020 15:01
Show Gist options
  • Save zafarivaev/270181afdc77778d3554b45a89f4f22a to your computer and use it in GitHub Desktop.
Save zafarivaev/270181afdc77778d3554b45a89f4f22a to your computer and use it in GitHub Desktop.
import RxSwift
import ReactiveCoordinator
enum ChooseCountryCoordinationResult {
case country(String)
case cancel
}
class ChooseCountryCoordinator: ReactiveCoordinator<ChooseCountryCoordinationResult> {
private let rootViewController: UIViewController
init(rootViewController: UIViewController) {
self.rootViewController = rootViewController
}
override func start() -> Observable<CoordinationResult> {
let viewController = ChooseCountryViewController()
let navigationController = UINavigationController(rootViewController: viewController)
let viewModel = ChooseCountryViewModel()
viewController.viewModel = viewModel
let country = viewModel.selectedCountry.map { CoordinationResult.country($0) }
let cancel = viewModel.didClose.map { _ in
CoordinationResult.cancel
}
rootViewController.present(navigationController, animated: true, completion: nil)
return Observable.merge(country, cancel)
.take(1)
.do(onNext: { _ in
viewController.dismiss(animated: true, completion: nil)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment