What changes in Swift 6 may break my codebase?

Asked on 2024-07-30

1 search

When migrating to Swift 6, there are several changes that may impact your codebase:

  1. Data-Race Safety: Swift 6 introduces a new language mode that enforces data-race safety. This means that the compiler will diagnose concurrent access to memory across your project. You may need to make changes to your code to fix data-race safety errors. This is an opt-in feature, so you can adopt it module by module when you are ready (Platforms State of the Union).

  2. Non-Copyable Types: Swift 6 introduces non-copyable types, which suppress the default copyability of Swift types. This is useful for scenarios where you want to express unique ownership, such as managing system resources like files. This change may require you to refactor parts of your code that rely on the default copy behavior (What’s new in Swift).

  3. Concurrency Checking: Swift 6 includes complete concurrency checking, which ensures that non-sendable values are not passed across active isolation boundaries. This may result in compiler warnings or errors if your code does not adhere to these new concurrency rules (What’s new in Swift).

  4. Compiler Diagnostics: The new Swift 6 compiler diagnostics will guide you towards places in your code that need fixing, especially related to concurrency and data-race safety. This can help you methodically eliminate potential bugs but may also require code adjustments (Migrate your app to Swift 6).

  5. Global Variables and Instances: You may need to review and update global variables and instances to ensure they are concurrency-safe. For example, changing a global variable from var to let if it does not need to be mutated (What’s new in Xcode 16).

For a detailed guide on migrating your app to Swift 6, you can refer to the session Migrate your app to Swift 6.

What changes in Swift 6 may break my codebase? | Ask WWDC