title: Get cell index from tableviewcell
body: <p>Hey I have this tableview controller that list restaurants from my database. what I want to do is if the cell/row is selected it opens a more detail page about the restaurant. for some reason I can't retrieve the index or its not going to the   func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) to give me index here is what I have:   </p>
  
  <pre><code>class HomeTableViewController: UITableViewController{
  
  
  var restaurantArray = [Restaurant]()
  var resTransfer: Restaurant?
  var resName: String?
  
  
  
  var dataBaseRef: FIRDatabaseReference! {
      return FIRDatabase.database().reference()
  }
  
  
  override func viewDidLoad() {
      super.viewDidLoad()
      title = "Home"
      navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Main Menu", style: .plain, target: self, action: #selector(SSASideMenu.presentLeftMenuViewController))
  }
  
  override func viewWillAppear(_ animated: Bool) {
      super.viewWillAppear(true)
      fetchRestaurants()
  }
  
  func fetchRestaurants(){
      FIRDatabase.database().reference().child("AthensRestaurants/Restaurants").observe(.value, with: { (snapshot) in
          var results = [Restaurant]()
  
          for res in snapshot.children{
              let res = Restaurant(snapshot: res as! FIRDataSnapshot)
              results.append(res)
          }
  
          self.restaurantArray = results.sorted(by: { (u1, u2) -&gt; Bool in
              u1.name &lt; u2.name
          })
          self.tableView.reloadData()
  
  }) { (error) in
  print(error.localizedDescription)
  }
  }
  
  // MARK: - Table view data source
  // MARK: - Table view data source
  
  override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      // #warning Incomplete implementation, return the number of rows
      return restaurantArray.count
  }
  
  
  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: "restaurantsCell", for: indexPath) as! RestaurantsTableViewCell
  
      // Configure the cell...
  
      cell.configureCell(res: restaurantArray[indexPath.row])
  
      return cell
  }
  
  
  
  
  func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
      print("Row \(indexPath.row)selected")
      resTransfer = restaurantArray[indexPath.row]
      resName = restaurantArray[indexPath.row].name
      print(resName as Any)
      performSegue(withIdentifier: "RestaurantDetailView", sender: self)
     }
  
  
  
  
  
  
  
  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     if(segue.identifier == "RestaurantDetailView") {
        let vc = segue.destination as! RestaurantDetailViewController
         vc.resNam = restaurantArray.first?.name //instead of first should be index of cell! 
          print(vc.resNam! as String)
      }
  }   
  }
  </code></pre>