Skip to content

Instantly share code, notes, and snippets.

@paradoxeth
Created September 23, 2019 06:06
Show Gist options
  • Save paradoxeth/0a778a2b6b482794e4af20869dca552b to your computer and use it in GitHub Desktop.
Save paradoxeth/0a778a2b6b482794e4af20869dca552b to your computer and use it in GitHub Desktop.
Debounce UIButton
extension UIButton {
/// Default debounce delay for UIButton taps. Allows delay to be updated globally.
static var debounceDelay: Double = 0.5
/// Debounces button taps with the specified delay.
func debounce(delay: Double = UIButton.debounceDelay) {
isEnabled = false
let deadline = DispatchTime.now() + delay
DispatchQueue.main.asyncAfter(deadline: deadline) { [weak self] in
self?.isEnabled = true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment