ios - Make NSTimer continue after closing and opening the game -


i making clicker game , need have nstimers continue after closing application. looked first not find suitable answer swift. think can use userdefaults not sure how apply it. sorry if duplicate question, know there lot of information on this.

var timervar = nstimer.scheduledtimerwithtimeinterval(4, target: self,      selector: selector("selectorname"), userinfo: nil, repeats: true)  func selectorname(){     var scoredefault = nsuserdefaults.standarduserdefaults()     scoredefault.setvalue(score, forkey: "score")     scoredefault.synchronize()     score+=1     scorelbl.text = "\(score)" } 

you can't pause , continue timer. have invalidate , create new one. record time @ moment start timer, , when pause it, figure out amount of elapsed time , use figure out how time remains. create new timer amount of remaining time calculated.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -