We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Given this SwiftUI code:
struct ContentView: View { @ObservedObject var viewModel = ViewModel() var body: some View { ... } class ViewModel: ObservableObject, TaskRunnerListener { @Published var taskText: String = "Hello, World" init() { WendyConfig.addTaskRunnerListener(self) } func runningTask(_ task: PendingTask) { self.taskText = "Running task..." } func allTasksComplete() { self.taskText = "All tasks complete!" } } }
If I run this code, I will get runtime errors saying that I should be updating the self.taskText value on the main thread, not background.
self.taskText
I resolve these errors if I do:
class ViewModel: ObservableObject, TaskRunnerListener { func runningTask(_ task: PendingTask) { Task { @MainActor in self.taskText = "Running task..." } } }
All listeners should be called on main actor.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Given this SwiftUI code:
If I run this code, I will get runtime errors saying that I should be updating the
self.taskText
value on the main thread, not background.I resolve these errors if I do:
All listeners should be called on main actor.
The text was updated successfully, but these errors were encountered: