0
votes

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

2
Yes, you can. TimeInterval is just a typealias for Double. You can use how many decimal places that you like (of course at some point it will become pretty imprecise, but with two decimal paces you will be fine). - inexcitus
Ok nice. Thanks! - adri567

2 Answers

1
votes

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

1
votes

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