swift - NSTimer.scheduledTimerWithTimeInterval() with variable delay -


i have function need called every x second. @ begining x = 5 everytime calls function x need decrement number. know how if x constant:

override func didmovetoview(view: skview) {     nstimer.scheduledtimerwithtimeinterval(5, target: self, selector: selector("function"), userinfo: nil, repeats: true) }  func function(){     println("test") } 

how decrement delay between each function calls each time gets called?

i change code this:

var timeduration: nstimeinterval = 5  override func didmovetoview(view: skview) {    nstimer.scheduledtimerwithtimeinterval(timeduration, target: self, selector: selector("function"), userinfo: nil, repeats: false) }  func function(){     println("test")     timeduration -= 1     if timeduration > 0{         nstimer.scheduledtimerwithtimeinterval(timeduration, target: self, selector: selector("function"), userinfo: nil, repeats: false)     } } 

this should work, have not tested it.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -