Skip to content

Instantly share code, notes, and snippets.

@inre
Created April 27, 2015 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inre/b5145527131d05fdb716 to your computer and use it in GitHub Desktop.
Save inre/b5145527131d05fdb716 to your computer and use it in GitHub Desktop.
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