Created
November 4, 2016 12:25
-
-
Save billwang1990/fcb52e0071f47201180d4f50fa2a2950 to your computer and use it in GitHub Desktop.
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
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