Can someone explain why Xcode (w Swift 5.6 or later) gives a "must be marked @Sendable" warning in one case but not the other?
Case 1:
func myFunc() {
@MainActor finishOnMain(_ foo: Foo) {
// do something with foo
}
Task {
if let foo = await GetFoo() {
finishOnMain(foo)
}
}
}
Generates warning: "Concurrently-executed local function must be marked sendable"
Case 2:
func myFunc() {
Task {
if let foo = await GetFoo() {
await MainActor.run {
// do something with foo
}
}
}
}
No warning.
Of course Case 2 doesn't use a local function so the warning wouldn't be exactly the same, but I would think it suffers from the same problem. Maybe this is just a bug/limitation of Xcode? Also I realize that marking the class Foo (or whatever) as @Sendable fixes the problem, but for me it's not always possible.