Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
private class BlockHandler: NSObject {
var block: (() -> Void)?
@objc func runBlock() {
private extension Timer {
class func iOS9Ready_scheduledTimer(withTimeInterval interval: TimeInterval, repeats: Bool, block: @escaping (Timer) -> Swift.Void) -> Timer {
if #available(iOS 10.0, *) {
return scheduledTimer(withTimeInterval: interval, repeats: repeats, block: block)
} else {
let blockHandler = BlockHandler()
let timer = Timer.scheduledTimer(timeInterval: interval, target: blockHandler, selector: #selector(BlockHandler.runBlock), userInfo: nil, repeats: repeats)
blockHandler.block = { [weak timer] in
guard let timer = timer else { return }
return timer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.