title: Remove Notification when UITableView row is deleted (Swift)
body: <p>I have a view controller with multiple UITableviews. I want when a row is deleted from a tableview to remove the notification associated with this row, here is my code but I get the error <code>Index out of range</code> here is a link to my project if anyone want to test it: <a href="https://files.fm/f/nwx8e7je" rel="nofollow noreferrer">https://files.fm/f/nwx8e7je</a></p>
  
  <p>My code: it works without a simple string but with the index row I get the error.</p>
  
  <pre><code>func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
  
      if editingStyle == .delete {
  
          if tableView == ScheduleTableView{
  
  
              let defaults = UserDefaults.standard
              var myarray = defaults.stringArray(forKey: "ScheduleArray") ?? [String]()
              var myarray2 = defaults.stringArray(forKey: "ScheduleTimeArray") ?? [String]()
  
            // Remove Row
              myarray.remove(at: indexPath.row)
              myarray2.remove(at: indexPath.row)
              defaults.set(myarray, forKey: "ScheduleArray")
              defaults.set(myarray2, forKey: "ScheduleTimeArray")
              ScheduleTableView.deleteRows(at: [indexPath], with: .fade)
              UserDefaults.standard.synchronize()
  
  
  
             // Remove Notification
              let center = UNUserNotificationCenter.current()
              let arrayToSearch = myarray[indexPath.row] as String
              center.getPendingNotificationRequests { (notifications) in
                  for item in notifications {
                      if(item.identifier.contains(arrayToSearch)) {
                          center.removePendingNotificationRequests(withIdentifiers: [item.identifier])
                      }
                  }
              }
  
  
          }
  
          if tableView == GoalsTableView{
  
  
          }
   }
  </code></pre>