I have a view that is updated asynchronously when it appears. It is updated via a publisher that gets some data and displays them
I put this view inside a ForEach wrapped in a List (but is the same as in a ScrollView).
The problem is as long as I scroll, the child views that appear are not updated until I release the finger from the screen.
I found a solution (following this question) putting inside the ObservableObject this queue:
and adding .receive(on: queue) to the publisher.
It seems to work but when I do this SwiftUI complies saying:
I put this view inside a ForEach wrapped in a List (but is the same as in a ScrollView).
The problem is as long as I scroll, the child views that appear are not updated until I release the finger from the screen.
I found a solution (following this question) putting inside the ObservableObject this queue:
Code Block private let queue = DispatchQueue(label: "datafetching.queue", attributes: .concurrent)
and adding .receive(on: queue) to the publisher.
It seems to work but when I do this SwiftUI complies saying:
As expected, some child views started updating wrongly.Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.