I created a timer and set it to repeat every 30 seconds
the timer waits 30 seconds to run the first time, then another 30 seconds for the second time, I wanted it to run the first time without the 30 seconds, is there any way?
Timer.scheduledTimer(withTimeInterval: 30, repeats: true) { timer in
if iteration >= 0 {
runCommands()
iteration -= 1
if iteration == 0 {exit(0)}
}
}
>Solution :
Just call fire. It does what the name implies.
Timer.scheduledTimer(withTimeInterval: 30, repeats: true) { timer in
if iteration >= 0 {
runCommands()
iteration -= 1
if iteration == 0 {exit(0)}
}
}.fire()