Learn Courses My Dashboard

How to remove local notification using uuiString

I’m new to iOS development. My question is how do you remove a local notification using a uuidString as the identifier since it creates a new identifier every time a new notification is created. I know that in order to remove pending notifications you can use methods to remove them all or to remove them with a hard coded identifier String such as UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: “identifier”), but how can you remove a individual pending notification using uuidString.
Here is a sample of my code where i create the notifications and where i would like to delete it:

 public var complationL: ((String,String,String)->Void)?
    
    @objc func saveButtonPressed(){
        
        if let titleText = titleTextFieldL.text, !titleText.isEmpty,
           let bodyText = bodyViewField.text, !bodyText.isEmpty,
           let searchText = locationSearchBar.text, !searchText.isEmpty{
            
            complationL?(titleText,bodyText,"\(segmentedControl.titleForSegment(at: segmentedControl.selectedSegmentIndex)!): \(searchText)")
            
            if segmentedControl.selectedSegmentIndex == 0{
                if let center = defaults.coordinate(forKey: "NCoordinates"){
                    let content = UNMutableNotificationContent()
                    content.title = titleText
                    content.body = bodyText
                    content.sound = .default
                    let uuidStringEntry = UUID().uuidString
                    let region = CLCircularRegion(center: center, radius: 300.0, identifier: uuidStringEntry)
                    region.notifyOnEntry = true
                    region.notifyOnExit = false
                    let trigger = UNLocationNotificationTrigger(region: region, repeats: false)
                    let notificationRequest = UNNotificationRequest(identifier: uuidStringEntry, content: content, trigger: trigger)
                    UNUserNotificationCenter.current().add(notificationRequest) { error in
                        if error != nil{
                            print("Error providing Arriving notification")
                        }else{
                           
                            print("Succesfully provided Arriving notification")
                        }
                    }
                }
            }else if segmentedControl.selectedSegmentIndex == 1{
                if let center = defaults.coordinate(forKey: "NCoordinates"){
                    
                    let content = UNMutableNotificationContent()
                    content.title = titleText
                    content.body = bodyText
                    content.sound = .default
                    let uuidStringExit = UUID().uuidString
                    let region = CLCircularRegion(center: center, radius: 300.0, identifier: uuidStringExit)
                    region.notifyOnEntry = false
                    region.notifyOnExit = true
                    let trigger = UNLocationNotificationTrigger(region: region, repeats: false)
                    let notificationRequest = UNNotificationRequest(identifier: uuidStringExit, content: content, trigger: trigger)
                    UNUserNotificationCenter.current().add(notificationRequest) { error in
                        if error != nil{
                            print("Error providing Leaving notification")
                        }else{
                            print("Succesfully provided Leaving notification")
                        }
                    }
                }
            }
            
        }
        
    }
    
}

    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
        return .delete
    }
    
    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete{
            tableView.beginUpdates()

            context.delete(reminder[indexPath.row])
            reminder.remove(at: indexPath.row)
          
            tableView.deleteRows(at: [indexPath], with: .fade)
            
            tableView.endUpdates()
            saveData()
        }
    }