Hello, I'm trying to perform simple async tasks wrapped in a Task struct but the compiler always says "error: cannot find 'Task' in scope" using XCode 13 with macOS 12's last beta
Even the simplier playground like this one, fails:
import Foundation
func foo() async -> String {
await withUnsafeContinuation { continuation in
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
continuation.resume(returning: "Hello")
}
}
}
func bar() {
Task {
let text = await foo()
print(text)
}
}
Results in:
error: MyPlayground.playground:13:5: error: cannot find 'Task' in scope
Task {
^~~~
So... is this normal or am I missing something basic (and stupid)?
Thanks
Thanks for sharing your experience. I could have reproduced the issue on Big Sur 11.6 (iOS Blank playground). (With additional
error: cannot find 'withUnsafeContinuation' in scope
.) I do not think this is normal and you should better send a bug report to Apple.Thanks to Claude31, I could have explored a little more. Instead of
import UIKit
,import _Concurrency
(in addition toimport Foundation
) will make it. What is odd is we do not needimport _Concurrency
in app projects. (You should not useimport _Concurrency
in actual projects, it may be treated as using a private framework.) And one more odd thing isimport _Concurrency
can be found when I see the generated header forFoundation
by Cmd-clicking the lineimport Foundation
.