Reputation: 977
I have created an enum named Task
in my project. Now I want to use the Swift Task
(https://developer.apple.com/documentation/swift/task).
When I want to use Swift Task
I wrote:
Swift.Task { ... }
but I get the error: Module 'Swift' has no member named 'Task'
Upvotes: 7
Views: 1826
Reputation: 29918
In order to support backdeployment of Swift concurrency features to older operating systems, Swift builds the concurrency APIs into a separate library which can be shipped separately from the Swift standard library. This swift_Concurrency
library is exposed as an implicit module called _Concurrency
, which is re-exported from the Swift standard library.
However, the Swift concurrency classes and types still belong to this implementation-only library, so in order to disambiguate, you'll need to write _Concurrency.Task
instead of Swift.Task
.
You can also see this in Xcode: if you refer to Task
in a new project, and ^-⌘-click on the symbol to jump to its definition, you'll find it in the _Concurrency
library interface:
Instead of explicitly writing out _Concurrency.Task
in order to disambiguate everywhere, consider the following:
typealias
for the type (e.g. typealias SwiftTask = _Concurrency.Task
) if you prefer your own Task
type taking precedence, and don't want to rename itasync
/await
and Task
are major new language/stdlib features that are going to be influential for a long time, so it may make sense to pick a less general word if the stdlib is going to be reserving that one going forwardUpvotes: 14