I have two timers that run at different time intervals, one of which is added to a runloop.
let timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in
// do some stuff
}
let timer2 = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { timer in
// do some other stuff
}
RunLoop.current.add(timer2, forMode: RunLoop.Mode.common)
I have a condition which requires the execution logic of the two timers do not run at the same time since they are both modifying the same data structures.
Is this already guaranteed by iOS? If not, what's the best way I can ensure this happens?
If you schedule both two timers, nothing ensure they'll fired at the same time.
You could ensure it by, schedule timer2 in fire block of timer1, an so on...