RxSwiftCommunity/RxSegue

Name: RxSegue

Owner: RxSwift Community

Description: null

Created: 2016-03-19 11:32:26.0

Updated: 2018-05-04 13:13:12.0

Pushed: 2017-11-27 05:27:47.0

Homepage: null

Size: 1962

Language: Swift

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

RxSegue

Reactive generic segue, implemented with RxSwift.

Build Status Version License Platform

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Example

RxSegueExample

s ViewController: BaseViewController {
let disposeBag = DisposeBag()
@IBOutlet var pushButton: UIButton!
@IBOutlet var presentButton: UIButton!
@IBOutlet weak var dismissButton: UIButton!

var voidSegue: AnyObserver<Void> {
    return ModalSegue(fromViewController: self,
        toViewControllerFactory: { (sender, context) -> SecondViewController in
            return SecondViewController()
    }).asObserver()
}

var profileSegue: AnyObserver<ProfileViewModel> {
        return NavigationSegue(fromViewController: self.navigationController!,
            toViewControllerFactory: { (sender, context) -> ProfileViewController in
                let profileViewController: ProfileViewController = ...
                    profileViewController.profileViewModel = context
                return profileViewController
        }).asObserver()
}

override func viewDidLoad() {
    super.viewDidLoad()

    presentButton.rx.tap
        .bindTo(voidSegue)
        .addDisposableTo(disposeBag)

    pushButton.rx.tap
        .map {
            return ProfileViewModel(name: "John Doe",
                email: "JohnDoe@example.com",
                avatar: UIImage(named: "avatar"))
        }
        .bindTo(profileSegue)
        .addDisposableTo(disposeBag)
}


Installation

RxSegue is available through CocoaPods. To install it, simply add the following line to your Podfile:

"RxSegue"
License

RxSegue is available under the MIT license. See the LICENSE file for more info.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.