adri567
adri567

Reputation: 661

scheduledTimer with two decimal

Is it possible to use schedulerTimer with two decimals like

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

the timeInterval is 0.10

Upvotes: 0

Views: 248

Answers (2)

Vicky_Vignesh
Vicky_Vignesh

Reputation: 592

yes you can do it by using TimeInterval and replace your desired value by 0.5

let timer = Timer.scheduledTimer(timeInterval: TimeInterval(0.5), target: self, selector: #selector(//yourMethod), userInfo: nil, repeats: false)

So the scheduledTimer in Foundation is

open class func scheduledTimer(timeInterval ti: TimeInterval, target aTarget: Any, selector aSelector: Selector, userInfo: Any?, repeats yesOrNo: Bool) -> Timer

where the TimeInterval is

public typealias TimeInterval = Double

Upvotes: 1

Glenn Posadas
Glenn Posadas

Reputation: 13283

Definitely.

Just take noted that the timeInterval parameter in that scheduedTimer method is described as:

The number of seconds between firings of the timer. If ti is less than or equal to 0.0, this method chooses the nonnegative value of 0.1 milliseconds instead.

doc: https://developer.apple.com/documentation/foundation/timer/1412416-scheduledtimer

Upvotes: 1

Related Questions