Why did Apple create the @background annotation? Wasn’t a nonisolated async method already global?

Asked on 2025-07-21

1 search

Apple introduced the @background annotation to provide a more explicit way to manage concurrency in Swift, particularly when dealing with tasks that should run on a background thread. While nonisolated async methods are indeed global in the sense that they are not tied to a specific actor, the @background annotation offers a clear and explicit way to indicate that a method should always run on a background thread. This helps in maintaining code clarity and ensuring that tasks are offloaded to the background, which is crucial for keeping apps responsive, especially when performing CPU-intensive tasks.

In the session Migrate your app to Swift 6, it is discussed how Swift concurrency makes guarantees explicit, and how annotations like @background can help in managing these guarantees effectively. This approach is part of Swift's broader strategy to make concurrent code safer and more predictable by providing clear isolation guarantees and reducing the risk of data races.