Search code examples
xcodeswiftnstimer

How does one change/update the time interval in an NSTimer?


I need to change the time interval once it has fired once

secondTimer = NSTimer.scheduledTimerWithTimeInterval(count, target:self, selector: Selector("update1"), userInfo:nil, repeats:false)

for example I want to change count to 1


Solution

  • You can't. Invalidate the timer, and create a new one with a different time interval.

    You can change the fire time. So if you want to change the time interval after the first firing only, create the timer with that time interval, then change the firing time so that the timer is fired the first time at the time you want.