title: Passing values between ViewControllers based on list selection in Swift
body: <p>I'm trying to pass the selected index number of a listView selection from one ViewController to another but am running into an issue with the tableView didSelectRowAtIndexPath delegate runs slightly later than the prepareForSegue function. </p>
  
  <p>Basically, in didSelectRowAtIndexPath, I seta variable, which is then picked up in the prepareForSegue. The issue is that prepareForSegue seems to run the second that the cell is selected and before the didSelectRowAtIndexPath function is called so my variable is not passed.</p>
  
  <p>My main bits of code are:</p>
  
  <p>tableView didSelectRowAtIndexPath delegate, which sets 'selectedResult'...</p>
  
  <pre><code>func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
      selectedResult = indexPath.item
      txtNameSearch.resignFirstResponder()    //get rid of keyboard when table touched.
      println("saved result")
  
  
      //tableView.deselectRowAtIndexPath(indexPath, animated: false)
      //var tappedItem: ToDoItem = self.toDoItems.objectAtIndex(indexPath.row) as ToDoItem
      //tappedItem.completed = !tappedItem.completed
      //tableView.reloadData()
  
  }
  </code></pre>
  
  <p>prepareForSegue function which sends the variable as 'toPass' to the other ViewController ('detailViewController'):</p>
  
  <pre><code>override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!){
      if (segue.identifier == "detailSeque") {
          println("preparing")
          var svc = segue!.destinationViewController as detailViewController
          svc.toPass = selectedResult
  
          //println(tableView.indexPathsForSelectedRows().
          //svc.toPass = tableView.indexPathForSelectedRow()
  
      }
  }
  </code></pre>
  
  <p>Thanks in advance</p>