Created
January 23, 2016 02:06
-
-
Save jtbandes/89bdb8a745b9f65d60a1 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
extension NSTimer | |
{ | |
private class Trampoline | |
{ | |
typealias Handler = @convention(block) (NSTimer) -> Void | |
@objc static func handleTimer(timer: NSTimer) { | |
let handler = unsafeBitCast(timer.userInfo, Handler.self) | |
handler(timer) | |
} | |
} | |
static func scheduledTimerWithTimeInterval(interval: NSTimeInterval, repeats: Bool, usingBlock block: @convention(block) (NSTimer) -> Void) -> NSTimer | |
{ | |
return scheduledTimerWithTimeInterval(interval, target: Trampoline.self, selector: "handleTimer:", userInfo: unsafeBitCast(block, AnyObject.self), repeats: repeats) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment