Main actor-isolated 🍎 iOS

Swift 6: Main actor-isolated property 'x' can not be referenced from a nonisolated context / Sending 'x' risks causing data races

Strict concurrency checking found code that accesses main-actor state from another isolation domain, or passes non-Sendable values across actors.

Seen on: iOS

Meaning

Swift 6 language mode (and complete checking in Swift 5.10) enforces actor isolation and Sendable at compile time. Fix by isolating code to @MainActor, using await, making types Sendable, or restructuring ownership.

Common causes

  • Calling @MainActor APIs from nonisolated functions/closures
  • Passing non-Sendable classes into Tasks/actors
  • Global mutable state
  • Delegates/callbacks from frameworks not annotated

⚡ Quick fix

  1. Annotate the caller @MainActor or use await MainActor.run
  2. Make data types Sendable (structs, final classes with immutable state)
  3. Turn on checking gradually (SWIFT_STRICT_CONCURRENCY = targeted)

Detailed fix by platform

Swift

  1. swift
    func refresh() async {
        let data = try? await api.fetch()
        await MainActor.run { self.viewModel.items = data ?? [] }
    }

How to diagnose

  1. Isolation — Where is the property isolated?
  2. Types — Sendable conformance
  3. Mode — Swift 6 or 5 with complete checking?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.