Last active
January 29, 2020 15:42
-
-
Save Adobels/c37d025999e19438f28030da5be8e78a to your computer and use it in GitHub Desktop.
Reusable and InterfaceBuilder friendly Timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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