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