Created
February 20, 2017 23:32
-
-
Save Baza207/8fedf7195158520539f20f6d3cec4527 to your computer and use it in GitHub Desktop.
Timer extension to add basic block timers for pre-iOS 10.
This file contains hidden or 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
public extension Timer { | |
@discardableResult | |
public class func scheduledTimer(withTimeInterval interval: TimeInterval, block: @escaping (Timer) -> Void) -> Timer { | |
let fireDate = interval + CFAbsoluteTimeGetCurrent() | |
let timer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, fireDate, 0, 0, 0) { (runLoopTimer) in | |
block(runLoopTimer!) | |
}! | |
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, CFRunLoopMode.commonModes) | |
return timer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment