0
Please can someone explain to me how to stop a scheduled timer in latest swift version.
Timer.scheduledTimer I used to stop it with. Timer.invalidate() But this no longer seems to work. I’m trying to have a start button to make the label display and add +1 each 3 seconds. Then I want a stop button to just stop the timer. Most appreciated if someone could explain the simplest way to achieve this. Thanks team
3 Antworten
+ 1
i figured it out tial and error style
i used var stopNum
then inside the timer {} i used
if stopNum >= 1 {
Timer.invalidate()
}
then inside the stop button i used stopNum += 1
now when i hit stop it adds 1 and triggers the invalidate()
thanks for your answer though most appreciated im attempting to make a bitcoin bot for auto trading so many more problems infront of me :)
0
It should still be invalidate()
https://developer.apple.com/documentation/foundation/timer
Are you perhaps re-firing the timer?
Is the timer is scope of invalidate()?
0
Glad you got it sorted out