title: After selecting a TableView Cell, pass the data back to the previous View Controller in Swift
body: <p>There seems to be a lot of tutorials online for this, but I cant find one that passes the value back from a TableView Controller to the first View Controller. </p>
  
  <p>Here's my set up... The first ViewController has a textfield, when the user presses in it, it takes them to the second TableViewController, where they can select a country from the list. Once they have selected it, I want them to press the DONE button on the Navigation Bar, and then I want it to segue back to the first ViewController and show the Country they selected in the textfield (ready for them to press a button and the app continues etc...)</p>
  
  <p>From what I can work out, I need to do this in the DidSelectRowAtIndexPath method...? But I also keep seeing talk on unwind segues? Sorry I am new to Swift and iOS code, so would appreciate a clear answer on what is the best and easiest way to do this. Please see my code below for each controller:</p>
  
  <p><strong>ViewController</strong></p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController, UITextFieldDelegate {
  
  @IBOutlet var textField: UITextField!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
  }
  
  func textFieldShouldBeginEditing(textField: UITextField) -&gt; Bool {
  
  performSegueWithIdentifier("countryTableView", sender: self)
  
  return false
  
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  }
  </code></pre>
  
  <p><strong>TableViewController</strong></p>
  
  <pre><code>import UIKit
  
  class TableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
  
  @IBOutlet var tabeView: UITableView!
  
  var countryPicker = ["Colombia", "England", "France", "Germany", "Brazil", "Austria", "Spain", "Australia", "USA", "Berlin", "Thailand", "Northern Ireland", "New Zealand", "Hawaii", "Switzerland", "Sweeden", "Finland", "Turkey", "Russia", "Netherlands", "Japan"]
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
  }
  
  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
      return countryPicker.count
  }
  
  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
      let cell = tableView.dequeueReusableCellWithIdentifier("UITableViewCell") as! UITableViewCell
  
      cell.textLabel!.text = countryPicker[indexPath.row]
  
      cell.selectionStyle = UITableViewCellSelectionStyle.Blue
  
      return cell
  }
  
  }
  </code></pre>
  
  <p>Thanks in advance!</p>