Back to Swift Reference
⚡ ConcurrencyIntermediateSwift 5.5+ · default isolation option Swift 6.2

@MainActor & UI Updates

Guarantee UI code runs on the main thread — and understand Swift 6.2 default MainActor isolation.

UI state must be mutated on the main actor. SwiftUI views are MainActor-isolated, and you can annotate models or methods with @MainActor.

Swift 6.2 (Xcode 26) lets app targets opt into MainActor-by-default isolation, which removes most concurrency warnings in UI code. Use @concurrent or nonisolated for work that should leave the main actor.

mainactor.swift
1@MainActor
2@Observable
3final class FeedModel {
4    var items: [String] = []
5    var isLoading = false
6
7    func refresh() async {
8        isLoading = true
9        defer { isLoading = false }
10        items = await Self.fetchItems() // UI state updated on main actor
11    }
12
13    nonisolated static func fetchItems() async -> [String] {
14        // heavy work off the main actor
15        ["SwiftUI", "SwiftData", "StoreKit"]
16    }
17}

Common pitfalls

  • Do not reach for DispatchQueue.main.async in new code — use @MainActor or MainActor.run.

Still unclear? Ask BeeAI about @MainActor & UI Updates.

Get a tailored explanation, or paste your own code for a Swift 6 review. Free members get daily questions — Pro is unlimited.

Ask BeeAI

Become a Founding Pro member: unlimited BeeAI, upcoming Swift paths and every new reference entry first.

See Pro Plans