Why "error: cannot find 'Task' in scope" in Xcode Playground?

In Xcode Version 13.0 beta 3 (13A5192i), I just paste this example:

@MainActor
class Test {
    fileprivate var value: Int?

    func tryMe() {
        Task {
            self.value = nil
        }
    }
}

from Why don't I need an await in this example? - #2 by nikitamounier

and get these compile error:

 **Playground execution failed:**
 
 **error: MainActorInheritActorContext.xcplaygroundpage:3:1: error: unknown attribute 'MainActor'**
 
 **@MainActor**
 
 **^**
 
 **error: MainActorInheritActorContext.xcplaygroundpage:8:9: error: cannot find 'Task' in scope**
 
 **Task {**
 
 **^~~~**

Edit: this compiles fine in a iOS project. So why Xcode Playground not compile the same code?

1 Like

Swift playgrounds don’t seem to fully support concurrency yet.

You can use import _Concurrency to enable most features, but some features may be missing. For example, I don’t think async let is usable with this method.

1 Like

I'll just use iOS or macOS project to experiment with async/await then.

Thanks!