nonisolated
Generated on 10/3/2024
2 searches
In the context of Swift concurrency, the term "nonisolated" refers to a method or variable that does not have a specific isolation guarantee. This means that the method or variable can be accessed from any context, without the constraints of actor isolation.
In the session "Migrate your app to Swift 6" from WWDC 2024, it is explained that declaring a method as nonisolated means that, despite being part of a main actor isolated type, the specific method will not be isolated to the main actor. This is useful for callbacks that do not make promises about where they will be called back from. However, using nonisolated unsafe should be a last resort, as it places the burden of ensuring safety on the developer, bypassing Swift's compile-time guarantees.
For more details, you can refer to the session Migrate your app to Swift 6 (17:12).
Migrate your app to Swift 6
Experience Swift 6 migration in action as we update an existing sample app. Learn how to migrate incrementally, module by module, and how the compiler helps you identify code that’s at risk of data races. Discover different techniques for ensuring clear isolation boundaries and eliminating concurrent access to shared mutable state.
Consume noncopyable types in Swift
Get started with noncopyable types in Swift. Discover what copying means in Swift, when you might want to use a noncopyable type, and how value ownership lets you state your intentions clearly.
What’s new in Swift
Join us for an update on Swift. We’ll briefly go through a history of Swift over the past decade, and show you how the community has grown through workgroups, expanded the package ecosystem, and increased platform support. We’ll introduce you to a new language mode that achieves data-race safety by default, and a language subset that lets you run Swift on highly constrained systems. We’ll also explore some language updates including noncopyable types, typed throws, and improved C++ interoperability.