Swift 6 · Errors and concurrency

Update the UI on the main actor

Mark UI code @MainActor so it always runs on the main thread.

@MainActor
final class ViewModel: ObservableObject {
    @Published var items: [String] = []
}

Official Swift 6 documentation

More errors and concurrency commands

All errors and concurrency commands · Swift 6 cheatsheet

Was this page helpful?