title: Setting delegate to pass data from one tab to another
body: <p>I am using: XCode 8.2, Swift 3.0, iOS 10.2, iPhone 7.  I have a <code>Tab Bar Controller</code> with child <code>View Controllers</code>.</p>
  
  <p>I am trying to send data from one view controller to another.  </p>
  
  <p>I've looked up how to do this <a href="https://www.youtube.com/watch?v=KhqXUi1SF4s&amp;t=66s" rel="nofollow noreferrer">here</a> and <a href="https://stackoverflow.com/questions/27307903/swift-tab-bar-view-prepareforsegue">here</a> but the first link isn't quite what I want since he is talking about Storyboard segues which doesn't appear to be the same type of segues used when moving between tabs.  </p>
  
  <p>The tab in which I am trying to send data: </p>
  
  <pre><code>protocol SendResultsDelegate {
      func sendResults(data: String)
  }
  
  class SendingVC {
      ....
      if delegate != nil {
          let data = // some string here
          delegate?.sendResults(data: data!)
  
      }
  }
  </code></pre>
  
  <p>The tab in which I am trying to receive data and print it out: </p>
  
  <pre><code>import UIKit
  
  class ResultsViewController: UIViewController, SendResultsDelegate {
  
      @IBOutlet weak var resultsTextField: UITextView!
  
      func sendResults(data: String) {
          resultsTextField.text = data
      }
  }
  </code></pre>
  
  <p>And I am not sure if this is correct but...I also have a custom class attached to my Tab Bar Controller:</p>
  
  <pre><code>override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
      let resultsIndex = 2
  
      if item == (self.tabBar.items! as [UITabBarItem])[resultsIndex] {
          let sendingVC : SendingVC = segue.destinationViewController as! SendingVC
          SendingVC.delegate = self
      }
  }
  </code></pre>
  
  <p>I'm not sure if it should be the <code>tabBar</code> function or the <code>prepare</code> function.  I'm basically trying: when the user clicks the results tab, that delegate is set and then passes through the <code>if</code> statement check on the <code>ResultsViewController</code> which can display the text field.  Of course, this fails to even compile/build and I am unsure where to go from here.  Any help would be greatly appreciated.</p>