Hello everyone, hope someone can give me some advices or any other kind information because currently i am stuck.
I have a timer that i use to update the last cell of a Tableview to display a countdown timer. If i define the timer as a non-static var everything works as expected meaning that when attaching this type of timer to the Runloop with Runloop mode to common, regardless if i scroll up or down (fast or not) the countdown progress will be correctly updated.
The probem is that i need to use a static timer and when i attach the static timer to the Runloop with mode Default or Common as soon as i refresh the tableview or if i scroll too fast the timer will not keep the last cell update (basically the cell display the same countdown). The cell will be updated only the first time if a scroll to the bottom to see the last cell. As soon as i scroll too fast up/down or i refresh the table the static timer i guess will be invalidated because i have read that while scrolling the Runloop mode switch between default mode to tracking mode.
Does anyone know why with a local var to the cell the timer doesn't have this type of problem if i refresh the rableview or scroll too fast while with a static timer which is for example defined in the AppDelegate or in another controller or even in the same cell Class if there are these kind of problem as if the timer can't keep updating the UI correclty?
Is it because static var are store in a different part of memory in the App that accessing them is more slow than a local var?
Here the snippet code for both cases
// Attaching non-static timer to the Runloop nonStaticTimer = Timer(timeInterval: 1.0, target: self, selector: #selector(updateUI), userInfo: nil, repeats: true) RunLoop.current.add(nonStaticTimer, forMode: .common) // Attaching static Timer to the Runloop MyCell.staticTimer = Timer(timeInterval: 1.0, target: self, selector: #selector(updateUI), userInfo: nil, repeats: true) RunLoop.current.add(MyCell.staticTimer, forMode: .common)