title: Using protocols to pass data
body: <p>I've read <a href="https://stackoverflow.com/questions/25589240/trying-to-understand-protocol-delegates-in-swift">Trying to understand protocol/delegates in Swift</a>, <a href="https://stackoverflow.com/questions/25522912/passing-data-back-from-view-controllers-xcode">Passing data back from view controllers Xcode</a>, and <a href="https://stackoverflow.com/questions/25759945/pass-data-when-dismiss-modal-viewcontroller-in-swift">Pass data when dismiss modal viewController in swift</a> in an attempt to pass some data back and forth. I think I did exactly what the posts described yet, the data is not being passed. I'm missing something and I have no idea what. If you could point out what that is, that would be so awesome. Thank you in advance :)</p>
  
  <p>I should also mentioned that I presented the <code>TaskMessageViewController</code> using a modal segue. And I want to send data back to my <code>TaskListViewController</code>. I am currently using <code>unwindToSegue</code> to go back to the <code>TaskListViewController</code>.</p>
  
  <p>In my <code>Protocols.swift</code> file, I have the following code:</p>
  
  <pre><code>import Foundation
  
  protocol ReceiveMessageDelegate {
      func receiveMessageFromTaskMessageViewController (message: String)
  }
  </code></pre>
  
  <p>And in my inheritance declarations, I have:</p>
  
  <pre><code>class TaskListViewController: UIViewController, ReceiveMessageDelegate
  </code></pre>
  
  <p>And in my <code>TaskListViewController.swift</code>, I wrote:</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
  
      let taskMessageViewController = TaskMessageViewController()
      taskMessageViewController.delegate = self
  
  }
  
  func receiveMessageFromTaskMessageViewController (message: String) {
      print(message)
      print("Protocol works!")
  }
  </code></pre>
  
  <p>And in my <code>TaskMessageViewController.swift</code>, I wrote:</p>
  
  <pre><code>var delegate: ReceiveMessageDelegate?
  @IBAction func doneButtonTapped(sender: AnyObject) {
      self.delegate?.receiveMessageFromTaskMessageViewController("message from message View Controller")
  }
  </code></pre>
  
  <p>When I press the <code>done</code> button on the simulator, the <code>doneButtonTapped</code> gets executed. However, <code>print("Protocol Works")</code> never gets executed. Anybody have any suggestions?</p>