Reputation: 5332
I'm calling startTimer()
and getting "start timer" printed in the console, but the scheduled timer never fires. Any thoughts?
func startTimer() {
print("start timer")
let timerDidFire: (Timer) -> Void = { timer in
print("timer")
self.updateLabels()
}
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: timerDidFire)
}
Upvotes: 1
Views: 616
Reputation: 12687
Be sure that you're executing your timer in main thread. You can check current execution in thread by:
print(Thread.current)
If not main, call your timer here:
DispatchQueue.main.async {
// here is your timer
}
Upvotes: 4
Reputation: 7246
This below methods are working perfect in WatchOS 3 for Timer.
func startTimers() {
RefreshTimer = Timer.scheduledTimer(timeInterval: 60, target: self, selector: #selector(InterfaceController.RefreshData), userInfo: nil, repeats: true)
}
func stopTimers() {
RefreshTimer.invalidate()
}
Upvotes: 0