Escaping closure captures mutating 'self' 🍎 iOS

Swift: Escaping closure captures mutating 'self' parameter

A mutating method of a struct tries to capture self in an escaping closure, which Swift forbids.

Seen on: iOS

Meaning

Value types are copied; an escaping closure can’t keep a reference to a mutating struct. Use a class (reference type), @State/ObservableObject in SwiftUI, or capture the needed values instead.

Common causes

  • Struct method with async/escaping closure modifying self
  • SwiftUI view struct mutating properties in callbacks

⚡ Quick fix

  1. Move the logic into a class / ObservableObject
  2. Capture values, not self
  3. Use @State and update via the main actor

Detailed fix by platform

Swift

  1. swift
    @MainActor final class Loader: ObservableObject {
        @Published var items: [Item] = []
        func load() { Task { items = try await api.fetch() } }
    }

How to diagnose

  1. Type — Struct or class?
  2. Closure — Escaping?

🔧 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.