Skip to content

Instantly share code, notes, and snippets.

@Adobels
Last active January 29, 2020 15:42
Show Gist options
  • Save Adobels/c37d025999e19438f28030da5be8e78a to your computer and use it in GitHub Desktop.
Save Adobels/c37d025999e19438f28030da5be8e78a to your computer and use it in GitHub Desktop.
Reusable and InterfaceBuilder friendly Timer
class UITimer: NSObject {
@IBInspectable
var timeInterval: Double = 1
@IBInspectable
var repeats: Bool = false
var timer: Timer?
typealias TimerBlock = (Timer) -> Void
func scheduleWith(_ timerBlock: @escaping TimerBlock) {
timer?.invalidate()
timer = Timer.scheduledTimer(withTimeInterval: timeInterval, repeats: repeats, block: timerBlock)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment