devxoul/RxViewController

`rx.viewDidLoad` not work.

PleaseDont opened this issue Β· 2 comments

I used it with ReactorKit followed your excellent App Drrrible

Here's my code:

final class HomeViewController: BaseViewController, StoryboardView {

        override func viewDidLoad() {
                super.viewDidLoad()
                print("viewDidLoad normal πŸŽ‰")
        }

        func bind(reactor: HomeViewReactor) {
                self.rx.viewDidLoad
                        .subscribe(onNext: {
                                print("viewDidLoad Rx πŸŽ‰")
                        })
                        .disposed(by: disposeBag)

                self.rx.viewWillAppear.map { $0 }
                        .subscribe(onNext: {
                                print("viewWillAppear \($0)πŸŽ‰")
                        })
                        .disposed(by: disposeBag)
        }
}

Here's console outputs:

viewDidLoad normal πŸŽ‰
viewWillAppear falseπŸŽ‰

The rx.viewDidLoad did not trigger, did I miss something?

With StoryboardView the bind() method gets called after the view is loaded. You have to use:

  func bind(reactor: MyReactor) {
-    self.rx.viewDidLoad
+    Observable.just(Void())
      .map { Reactor.Action.foo }
      .bind(to: reactor.action)
  }

@devxoul Thank you so much :-)