Please can someone explain to me how to stop a scheduled timer in latest swift version. | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
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

21st Apr 2020, 10:41 PM
Kevin
3 ответов
+ 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 :)
21st Apr 2020, 11:07 PM
Kevin
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()?
21st Apr 2020, 10:50 PM
ChaoticDawg
ChaoticDawg - avatar
0
Glad you got it sorted out
21st Apr 2020, 11:08 PM
ChaoticDawg
ChaoticDawg - avatar