Created
April 27, 2015 11:20
-
-
Save inre/b5145527131d05fdb716 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
import Foundation | |
@objc class Timer: NSObject { | |
var timer: NSTimer? | |
var handler: (() -> ())! | |
let duration: Double | |
init(duration: Double) { | |
self.duration = duration | |
super.init() | |
} | |
func start(handler: () -> ()) { | |
self.handler = handler | |
self.timer = NSTimer.scheduledTimerWithTimeInterval(duration, target: self, selector: "call", userInfo: nil, repeats: true) | |
} | |
func stop() { | |
self.timer?.invalidate() | |
} | |
@objc func call() { | |
self.handler() | |
} | |
deinit { | |
println("deinit timer called") | |
self.timer?.invalidate() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment