Skip to content

Instantly share code, notes, and snippets.

@billwang1990
Created November 4, 2016 12:25
Show Gist options
  • Save billwang1990/fcb52e0071f47201180d4f50fa2a2950 to your computer and use it in GitHub Desktop.
Save billwang1990/fcb52e0071f47201180d4f50fa2a2950 to your computer and use it in GitHub Desktop.
public typealias TimerExcuteClosure = @convention(block) () -> ()
extension Timer {
private class TimerActionBlockWrapper : NSObject {
var block : TimerExcuteClosure
init(block: @escaping TimerExcuteClosure) {
self.block = block
}
}
public class func YQ_scheduledTimerWithTimeInterval(_ ti:TimeInterval, closure: @escaping TimerExcuteClosure, repeats yesOrNo: Bool) -> Timer {
return self.scheduledTimer(timeInterval: ti, target: self, selector: #selector(Timer.excuteTimerClosure(_:)), userInfo: TimerActionBlockWrapper(block: closure), repeats: true)
}
@objc private class func excuteTimerClosure(_ timer: Timer) {
if let action = timer.userInfo as? TimerActionBlockWrapper {
action.block()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment