Post

Replies

Boosts

Views

Activity

Reply to AsyncRenderer causes crashes in ForEach when in Swift 6 language mode
We ran into this exact crash three times in production (iOS 18+, Swift 6 mode) and spent a while chasing it, so here is what we found in case it helps. It's not really the runtime doing something wrong. ForEach.init declares its content closure as nonisolated, but any closure literal you write inside body is inferred @MainActor. The compiler lets that conversion through without a warning and quietly adds an executor check at the closure's entry. Then, while an animation is running, SwiftUI calls that closure from com.apple.SwiftUI.AsyncRenderer, and the check fails. What fixed it for us: mark the closure @Sendable, only read Sendable values inside it, and keep anything main-actor in the child view's body: ForEach(items) { @Sendable item in RowView(item: item) } Identity and transitions behave exactly as before. We checked the emitted IR to be sure: the executor check is gone. Since we shipped it, the crash has not come back on any release. Hope that saves someone the week we lost on it.
Topic: UI Frameworks SubTopic: SwiftUI
Sep ’26
Reply to AsyncRenderer causes crashes in ForEach when in Swift 6 language mode
We ran into this exact crash three times in production (iOS 18+, Swift 6 mode) and spent a while chasing it, so here is what we found in case it helps. It's not really the runtime doing something wrong. ForEach.init declares its content closure as nonisolated, but any closure literal you write inside body is inferred @MainActor. The compiler lets that conversion through without a warning and quietly adds an executor check at the closure's entry. Then, while an animation is running, SwiftUI calls that closure from com.apple.SwiftUI.AsyncRenderer, and the check fails. What fixed it for us: mark the closure @Sendable, only read Sendable values inside it, and keep anything main-actor in the child view's body: ForEach(items) { @Sendable item in RowView(item: item) } Identity and transitions behave exactly as before. We checked the emitted IR to be sure: the executor check is gone. Since we shipped it, the crash has not come back on any release. Hope that saves someone the week we lost on it.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Sep ’26