I'm trying to use Rxswift in an application embedded in Tabbar Controller.
I have three view controllers in the tabbar. There are few subscriptions in all view controllers. But for the sake of simplicity lets say first and second view controllers subscribe to the third view controller to get some values.
I get subscribed to the third view controller as coded;
func startSubscription() {
let settingsNavigationVC = self.tabBarController?.viewControllers![2] as! UINavigationController
let settingsVC = settingsNavigationVC.topViewController as! SettingsViewController
settingsVC.selectedUser.subscribe(onNext: { [weak self] user in
self?.userToShow = user
}).disposed(by: disposeBagForFirst)
}
This works fine if all the tabs are tapped before any data manipulation so all the subscription can start and all app works fine. But if a user directly taps to third vc after loading the app, and makes a change. Then the data at first vc gets updated since it is already loaded when the app started, but the data at second vc doesn't change since there is no subscription yet because the view was not loaded before the changes made in third vc.
I tried to do it with instantiate vc method but that doesn't work either, because with tab bar controllers there is no instantiating views more than once I suppose.
My question is; how can I make sure all the views get loaded before the user interacts with the app, or how should I change my subscription method in order to make it work regardless if all the tabs clicked(views loaded).
Thanks in advance.