Skip to content

Instantly share code, notes, and snippets.

@fluxsaas
Created July 15, 2010 06:06
Show Gist options
  • Save fluxsaas/476568 to your computer and use it in GitHub Desktop.
Save fluxsaas/476568 to your computer and use it in GitHub Desktop.
class Controller
attr_accessor :timer
def startTimer(sender)
@timer = Timer.new
timerThread = NSThread.alloc.initWithTarget(@timer,
selector:'startTimer:',
object:'dummy_obj' )
timerThread.start
end
end
class Timer
attr_accessor :input
def startTimer(to_process)
@startTime = Time.now
interval = NSTimer.timerWithTimeInterval 0.1,
target: self,
selector: "update_timer:",
userInfo: nil,
repeats: true
NSRunLoop.currentRunLoop.addTimer(interval, forMode: NSDefaultRunLoopMode)
NSRunLoop.currentRunLoop.runUntilDate(NSDate.distantFuture)
end
def update_timer(timer)
elapsed = Time.now - @startTime
@input.setDateValue(NSDate.dateWithString(@elapsed.to_s))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment