ios - Swift 2 Should I use 2 NSTimers or 1 for a delayed start timer -


i making ios app in swift 2 user select delay (from slider) length of timer. when user clicks start, timer wait delay time , start (by signaling beep). when reaches end of timer length, stop , signal beep.

is better use 1 or 2 timers. meaning, should create "delay" timer when reaches end of delay, starts actual timer. or, should use 1 timer beeps @ end of delay time, starts screen clock, , beeps , terminates timer @ end of official timer.

john

you need single timer:

declare within class:

var timer = nstimer() 

put in function start delay:

timer = nstimer.scheduledtimerwithtimeinterval(delaytime, target: self, selector: "delaytime", userinfo: nil, repeats: false) 

and need 2 functions:

func delaytime() {      timer = nstimer.scheduledtimerwithtimeinterval(timerspeed, target: self, selector: "usetimer", userinfo: nil, repeats: true) }  func usetimer() {     //do whatever want! } 

hope helps.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -