Sorry if this is a newbie question, I am very new to iOS & Swift. I have a timer, I know I could use 'CADisplayLink', but if I use it, my milliseconds in my timer will jump like 1, 3, 7... 67, 71... I don't need this, I need 1, 2, 3, 4, 5 ... 54, 55, 56 , 57... In iPhone 7, iPhone 7 Plus, iPhone 5 function pretty good, but in iPhone SE, iPad Retina, iPad Pro, iPad Air the timer is too much slow, so basically the timer is skewed.
The timer doesn't run as good as the one in the default timer app (FPS issue?)
I need milliseconds make each step:
func updateStopwatch() {
milliseconds += 1
print(milliseconds)
if milliseconds == 100 {
milliseconds = 0
seconds += 1
}
let millisecondsString = milliseconds > 9 ?"\(milliseconds)" : "0\(milliseconds)"
let secondsString = seconds > 9 ?"\(seconds)" : "\(seconds)"
stopWatchString = "\(secondsString).\(millisecondsString)"
labelTimer.text = stopWatchString
}
@IBAction func startStopButtonTapped(_ sender: Any) {
if isTimerRunning {
isTimerRunning = !isTimerRunning
timer = Timer.scheduledTimer(timeInterval: 0.001, target: self, selector: #selector(updateStopwatch), userInfo: nil, repeats: true)
}else{
isTimerRunning = !isTimerRunning
timer.invalidate()
}
}