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
Post a Comment