Skip to content

Swift 6 MainActor isolation issue? #106

@EddieLukeAtmey

Description

@EddieLukeAtmey

Hi, I'm writing like this in code swift 5.9, it's working:

UIStackView().then($0.addSubview).then {
    $0.axis = .vertical
    $0.addArrangedSubviews(...)
}

However, when I upgrade to swift 6.0 or 6.2, the compiler is complaining:

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

I tried config in build setting's Default actor isolation = MainActor but it's not working. i suspect the cause is in the spm defination:

// swift-tools-version:5.0

maybe this could help fix it? https://www.avanderlee.com/concurrency/default-actor-isolation-in-swift-6-2/

// swift-tools-version: 6.2
...
.target(
    name: "DefaultActorIsolationPackage",
    swiftSettings: [
        /// You can add a new `defaultIsolation` Swift setting to any of your SPM targets.
        .defaultIsolation(MainActor.self)
    ]
)

I'm not totally sure about this, as i'm not an expert on those Actors thingy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions