SwiftUI – make sure to publish values from the main thread (via operators like receive(on:)) on model updates

Just put @MainActor before defining your class that is supposed to act in the main thread. And it’s so simple in terms of using new Swift concurrency.

@MainActor class DocumentsViewModel: ObservableObject { ... }

There’s a lot of information about that in new WWDC 2021 videos or articles like that: Using the MainActor attribute to automatically dispatch UI updates on the main queue

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)