Guru Charan
Guru Charan

Reputation: 94

Performing navigation in mvvm with RxSwift

Iam using MVVM with RxSwift i have tried Coordinator and RxFlow to navigate between viewcontroller. Is there any simply approach to segue between viewcontroller with RxSwift

  viewModel.users.subscribe {
                            model in


                            self.walkthrough = WalkthroughModel(country: (model.element?.country)!, countryCode: (model.element?.countryCode)!,PhoneNumber:"")

                            DispatchQueue.main.async {
                                self.performSegue(withIdentifier: "Walkthrough_phone", sender: self)
                            }
                        }.dispose() 

these the normal approach iam doing right now but is there any way to bind segu to the button

Upvotes: 3

Views: 2268

Answers (2)

M Inomata
M Inomata

Reputation: 31

RxFlow may become the answer.

RxFlow is a navigation framework for iOS applications based on a Reactive Flow Coordinator pattern

https://github.com/RxSwiftCommunity/RxFlow

Upvotes: 3

Evgeniy Kleban
Evgeniy Kleban

Reputation: 6940

I think segue should be perform in view controller because it is UI action, and it has nothing to do with view model. You should hold reference to viewModel inside viewController class, so you can easy access it properties while do tap on button in view controller class.

Performing tap to button with RxSwift look like that:

btn.rx.tap
  .subscribe(onNext: { [weak self] _ in 
     // Do segue
  })
  .addDisposableTo(bag)

Upvotes: 0

Related Questions