I recently converted an app from individual controllers to a UITabBar
application. In this app I need to pass data from tab1-ViewController
to tab2-ViewController
, I used to do it through delegation but now the way I'm doing it's by accessing the properties from tab1 in tab2 and setting them directly there.
Is this considered a bad practice? If yes, what is the most common way to pass data between tabs in a UITabBarController app?
Here is the code...
Tab1 ViewController
class Tab1ViewController: UIViewController{
var name:String = ""
override func viewDidLoad() {
super.viewDidLoad()
/// Do something with name
}
}
Tab2 ViewController
class Tab2ViewController: UIViewController{
override func viewDidLoad() {
let tab1VC = self.tabBarController?.viewControllers?[0] as! Tab1ViewController
tab1VC.name = "John"
}
}