title: How to reference indexPath in prepareForSegue function (Swift 2.0)
body: <p>I'm new to Swift, and I've been scavenging StackOverflow for a couple hours trying to find a solution. This is what I have so far (that doesn't show a compilation error): </p>
  
  <pre><code>override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
      if segue.identifier == "addExpenseSegue"
      {
  
          let destination = segue.destinationViewController as! AddExpenses
  
          let indexPath = tableView.indexPathForSelectedRow
          destination.itemNameText = self.items[indexPath!.row] 
      }
  }
  </code></pre>
  
  <p>Basically I have an array of user-entered items, and I click a button to segue into another view controller that displays the selected item as a label. I'm trying to relay the contents of my tableView into a second view controller (called AddExpenses) in the form of a label. </p>
  
  <p>If I write <code>destination.itemNameText = "hey"</code> the code works just fine. </p>
  
  <p>Also, here's the code from my second view controller: </p>
  
  <pre><code>class AddExpenses: UIViewController
  
  {
      var itemNameText = String()
      @IBOutlet var ItemName: UILabel!
  
      @IBAction func CancelButton(sender: AnyObject)
      {
  
          dismissViewControllerAnimated(true, completion: nil)
      }
  
      override func viewDidLoad()
      {
          ItemName.text = itemNameText
      }
  </code></pre>
  
  <p>How can I get <code>indexPath.row</code> inside the <code>prepareForSegue</code> function? Any help is greatly appreciated. Thanks in advance.</p>
  
  <p>EDIT: Here's some more of my code. This is inside my main view controller: </p>
  
  <pre><code>func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return items.count
  }
  
  
  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell
  {
  
      let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
  
      // Labels stuff inside table
      cell.textLabel?.text = items[indexPath.row]
  
      return cell
  }
  
  // Does the swiping action for each cell
  func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -&gt; [UITableViewRowAction]?
  {
      let deletedRow:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
  
      let delete = UITableViewRowAction(style: .Normal, title: "Delete")
      {
          action, index in
          self.items.removeAtIndex(indexPath.row) // Take word out of the array
          tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic) // Remove entire row
          deletedRow.accessoryType = UITableViewCellAccessoryType.None // Take out checkmark
      }
      delete.backgroundColor = UIColorFromHex(0xff6347)
  
      let bought = UITableViewRowAction(style: .Normal, title: "Bought")
      {
          action, index in
  
          self.performSegueWithIdentifier("addExpenseSegue", sender: self)
  
      }
  
      bought.backgroundColor = UIColorFromHex(0x43CD80)
  
      return [bought, delete]
  }
  </code></pre>