title: swift timer invalidation inside tableView cell
body: <p>I'm a beginner just start learning swift for a few months now. Please help me with a timer invalidation issue. Feel free to make me feel stupid :). I know it's a bit messy and I'm willing to take pointer on how to do it better next time.</p>
  
  <pre><code>override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! CustomCustomerCell
      let appDelegate = UIApplication.shared.delegate as! AppDelegate
  
      let object = appDelegate.Queuelist[indexPath.row]
  
      if let genderInital = object.gender?.characters.first {
          cell.genderlabel.text = " \(genderInital)"
      }
      object.timerStarted()
  
  
      cell.waitedTimeLabel.text = "\(object.counter)"
  
      cell.nameLabel.text = object.name
      cell.languageLabel.text = object.language
      cell.reasonLabel.text = object.reasonOfVisit
      return cell
  }
  
  override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  
      var customerName: String?
  
  
      if let indexPathForName = tableView.indexPathForSelectedRow {
  
          let appDelegate = UIApplication.shared.delegate as! AppDelegate
          let selectedCustomer = appDelegate.Queuelist[indexPathForName.row]
          customerName = selectedCustomer.name
          }
  
  
      let alertController = UIAlertController(title: customerName, message: "message", preferredStyle: .alert)
  
      let cancelAction = UIAlertAction(title: "cancel", style: .cancel, handler: nil)
  
      let editAction = UIAlertAction(title: "edit", style: .default) {action -&gt; Void in
  
          self.performSegue(withIdentifier: "addSegue", sender: alertController)
          }
      let takeCustomerAction = UIAlertAction(title: "take customer", style: .default) {
          action -&gt; Void in
          if let indexpath = tableView.indexPathForSelectedRow {
              let appDelegate = UIApplication.shared.delegate as! AppDelegate
  
              let object = appDelegate.Queuelist[indexpath.row]
              object.timer?.invalidate()
              appDelegate.Queuelist.remove(at: indexpath.row)
              appDelegate.storedQueuelist()
              tableView.deleteRows(at: [indexPath], with: .fade)
          }
      }
  
      alertController.addAction(takeCustomerAction)
      alertController.addAction(editAction)
      alertController.addAction(cancelAction)
      self.present(alertController, animated: true, completion: nil)
  }
  </code></pre>