title: How to pass data from ViewController to a ViewController in a tab bar iOS?
body: <p>I'm trying to pass data from my main ViewController to another ViewController in a Tab Bar.</p>
  
  <p><a href="https://i.stack.imgur.com/5vfi3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5vfi3.png" alt="enter image description here"></a></p>
  
  <p>I have tried using the following code , and got an error <code>Could not cast value of type 'Test.FirstViewController'</code> to <code>'Test.ViewController'</code></p>
  
  <pre><code>override func viewWillAppear(_ animated: Bool)
  {
      super.viewWillAppear(animated)
      let tab1Controller = self.tabBarController?.viewControllers?.first as! ViewController
      print(tab1Controller.test)
  }
  </code></pre>