user13370778
user13370778

Reputation:

Make Timer start counting as soon as ViewDidLoad is called

I have set Timer in ViewDidLoad in this way:

let timer = Timer.scheduledTimer(
           timeInterval: 3, target: self, selector: #selector(handleAnimation),
       userInfo: nil, repeats: true)

But until it fires out the first handleAnimation method I need to wait for 3 seconds. Is there a way to make timer fire out the function as soon as the viewDidLoad function is executed?

Upvotes: 0

Views: 332

Answers (1)

vadian
vadian

Reputation: 285092

Tell the timer fo fire immediately.

let timer = Timer.scheduledTimer(
       timeInterval: 3, target: self, selector: #selector(handleAnimation),
   userInfo: nil, repeats: true)
timer.fire()

Upvotes: 2

Related Questions