what's @preconcurrency

Asked on 07/31/2024

1 search

The @preconcurrency attribute in Swift is used to mark code that was written before Swift's concurrency model was introduced. This attribute helps the compiler understand that certain parts of the code may not adhere to the concurrency safety guarantees provided by Swift's concurrency model.

In the context of migrating to Swift 6, the @preconcurrency attribute can be used temporarily to suppress concurrency warnings for code that hasn't been updated yet. However, once the code is updated to conform to Swift's concurrency model, this attribute can be removed.

For example, in the session Migrate your app to Swift 6, it is mentioned that after adding the @preconcurrency attribute to a protocol, the compiler warns that it is no longer needed once the protocol is guaranteed to be on the main actor. This indicates that the code has been updated to be concurrency-safe, and the attribute can be removed.

Relevant Sessions

  1. Migrate your app to Swift 6
  2. What’s new in Swift
  3. What’s new in Xcode 16

These sessions provide insights into the use of concurrency in Swift, the migration process to Swift 6, and the tools available in Xcode 16 to help with this transition.

what's @preconcurrency | Ask WWDC