I have a class with a timer (updating every millisecond).
class TimeCount {
let currentTimePublisher = Timer.TimerPublisher(interval: 0.001, runLoop: .main, mode: .common)
let cancellable: AnyCancellable?
init() {
self.cancellable = currentTimePublisher.connect() as? AnyCancellable
}
deinit {
self.cancellable?.cancel()
}
}
I also have a List() of TimerView objects
List() {
ForEach(self.timers) { timer in
TimerPlusView(timer: timer)
}
}
And inside each object i have a Text that updates its content listening to the timer
Text("\(currentTime.timeIntervalSince(timer.time ?? Date()))")
.font(.largeTitle)
.fontWeight(.bold)
.foregroundColor(.black)
.opacity(0.5)
.onReceive(timeCount.currentTimePublisher) { newCurrentTime in
self.currentTime = newCurrentTime
}
Thing is, after (not while) scrolling the list for about 100px, the timer stops working and the labels stop updating, and I have no idea why.
UPD: here's a link to the full project for reference. https://www.dropbox.com/s/47zoizfqp6upz1e/TimerMinimal.zip?dl=0