Skip to content

Fix Swift 6 @MainActor isolation error#107

Open
devxoul wants to merge 2 commits intomainfrom
fix/swift6-mainactor-isolation
Open

Fix Swift 6 @MainActor isolation error#107
devxoul wants to merge 2 commits intomainfrom
fix/swift6-mainactor-isolation

Conversation

@devxoul
Copy link
Owner

@devxoul devxoul commented Mar 10, 2026

Summary

Fix the Swift 6 strict concurrency error when using then/with/do with @MainActor-isolated types such as UIKit classes.

Closes #106

Problem

In Swift 6 strict concurrency, calling then on a @MainActor-isolated type like UIStackView produces:

Converting function value of type '@mainactor (UIStackView) throws -> Void' to '(UIStackView) throws -> Void' loses global actor 'MainActor'

This happens because the library was compiled with swift-tools-version:5.0 (Swift 5 language mode), where non-escaping closures do not inherit the caller's actor isolation.

Changes

Package.swift

  • Bump swift-tools-version from 5.0 to 6.0. In Swift 6 language mode, non-escaping closure parameters automatically inherit the caller's actor isolation — no API changes needed.
  • Update minimum deployment targets to macOS 10.13 / iOS 12 / tvOS 12 / watchOS 4 (required by Swift 6 toolchain).

Tests

  • Add 3 new @MainActor-annotated tests validating that then, with, and do compile and behave correctly with @MainActor-isolated types.

Context

  • Zero API surface changes. Existing consumers on Swift 6 get the fix automatically.
  • Consumers still on Swift 5.x should pin to a previous release, as the new swift-tools-version:6.0 requires Swift 6 tooling.

Testing

  • All existing tests pass.
  • 3 new tests (testThen_MainActorIsolated, testWith_MainActorIsolated, testDo_MainActorIsolated) verify the fix.

Summary by cubic

Fixes Swift 6 strict concurrency errors when calling then/with/do on @MainActor-isolated types by building Then in Swift 6 mode. Also updates minimum platform versions, adds @MainActor tests, and sets Tuist SWIFT_VERSION to 6.0.

  • Migration
    • Requires Swift 6 toolchain (swift-tools-version: 6.0).
    • Minimum targets: macOS 10.13, iOS 12, tvOS 12, watchOS 4.
    • If you need Swift 5.x, pin to a previous Then release.

Written for commit 3b2f791. Summary will update on new commits.

In Swift 6 language mode, non-escaping closures automatically inherit
the caller's actor isolation. This resolves the type mismatch error when
using then/with/do with @MainActor-isolated types such as UIKit classes.

Closes #106
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swift 6 MainActor isolation issue?

1 participant