The question was already asked some time ago. But I'm not able to find a nice solution matching to the current Swift version.
Cancel a timed event in Swift? (is already outdated)
How to cancel DispatchQueue.main.asyncAfter(deadline: time) in Swift3? (got no simple & right answer)
Swift 4 - How to cancel a specific call to DispatchQueue.main.asyncAfter
?
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
// my code
}
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
// just cancel this event!
}