Your can store the variable locally before using it as a parameter:
@MainActor struct Foo {
var num: Int { 42 }
nonisolated func foo(_ int: Int) async {}
func bar() async {
var num = num // sometimes a let works too, but not always
await foo(num)
}
}
I also ran into this issue, but am unable to build my project with the Swift 6.0.1 toolchain, as Xcode reports an SDK/toolchain mismatch when trying to import SwiftUI.
What is the status here ? I still see this error in Xcode 16.1 beta 3 with a string type being passed from a nonisolated function into a MainActor bound task.
@sasouth can you post a specific test case that shows the issue so I can try to reproduce. There may be something else going on.
In terms of the original issue, I just validated that we do not get any errors with the original test case of the OP in both Xcode 16 and Xcode 16.1 Beta 3.