20.7 C
Canberra
Thursday, February 26, 2026

Is 2025 the 12 months to completely undertake Swift 6? – Donny Wals


When Apple launched Xcode 16 final 12 months, they made the Swift 6 compiler accessible together with it. Which means that we are able to create new initiatives utilizing Swift 6 and its compile-time knowledge race protections.

Nonetheless, the massive query for a lot of builders is: Is 2025 the correct time to undertake Swift 6 totally, or ought to we persist with Swift 5 for now?

On this publish, I gained’t offer you a definitive reply. As a substitute, I’ll share my perspective and reasoning that will help you determine whether or not adopting Swift 6 is best for you and your mission(s).

The appropriate reply will depend on a great deal of variables just like the mission you’re employed on, the group you’re employed with, and your information of Swift Concurrency.

Xcode 16, present initiatives, and Swift 6

In case you’ve opened an present mission in Xcode 16, you won’t have observed any fast modifications. Whereas the Swift 6 compiler is utilized in Xcode 16 for all initiatives, Xcode defaults to the Swift 5 language mode for present initiatives.

In case you’ve skilled earlier main migrations in Swift, you’ll keep in mind that Xcode would often immediate you to make modifications to your mission with a purpose to be sure your mission nonetheless works. This occurred for the migration from Swift 1.2 to Swift 2, and from Swift 2 to Swift 3.

We received a brand new compiler, and we have been compelled to undertake the brand new Swift language model that got here together with it.

Since then, the compiler has gained some “language modes”, and the Swift 6 compiler comes with a Swift 5 language mode.

The Swift 5 language mode permits the Swift 6 compiler to operate with out implementing all of the stricter guidelines of Swift 6. For instance, the Swift 5 language mode will make it in order that compile-time knowledge race protections are usually not turned on.

So, once we discuss adopting Swift 6, we’re actually speaking about opting into the Swift 6 language mode.

Current initiatives which might be opened in Xcode 16 will, robotically, use the Swift 5 language mode. That’s why your mission nonetheless compiles completely tremendous with out adopting Swift 6.

What about new initiatives?

New initiatives in Xcode 16 additionally default to Swift 5 language mode. Nonetheless, Swift packages created with the Swift 6 toolchain default to Swift 6 language mode until explicitly configured in any other case. This distinction is necessary, as a result of whenever you create new packages you’re working in a special language mode than mission (and that’s completely tremendous).

In case you’re inquisitive about enabling the Swift 6 language mode for present initiatives or packages, I’ve some weblog posts about that right here:

Challenges of Adopting Swift 6

Switching to Swift 6 language mode could make initiatives that compiled simply tremendous with Swift 5 break utterly. For instance, you’ll run into errors about capturing non-sendable parameters, sendable closures, and actor isolation.

Some fixes are easy—like making an immutable object explicitly sendable or refactoring objects which might be utilized in async capabilities into actors. Nonetheless, different points, particularly these involving crossing isolation boundaries, might be a lot trickier to repair.

For instance, including actors to resolve sendability errors usually requires refactoring synchronous code into asynchronous code, resulting in a ripple impact all through your codebase. Even seemingly easy interactions with an actor require await, even for non-async capabilities as a result of actors function in their very own isolation contexts.

Adopting actors is often a job that can take a lot, for much longer than you may anticipate initially.

Resolving errors with @MainActor

A typical workaround is to liberally apply @MainActor annotations. Whereas this reduces concurrency-related errors by forcing most code to run on the primary thread, it’s not all the time the answer that you just’re in search of. Whereas not inherently incorrect, this method must be used with warning.

Lowering crossing of isolation boundaries

Apple acknowledges the challenges of adopting Swift 6, particularly for present initiatives. One vital facet of Swift Concurrency that may make adoption tough is how non-isolated asynchronous capabilities inherit isolation contexts. Presently, nonisolated async capabilities run on a background thread until explicitly remoted, which might result in pointless crossing of isolation boundaries.

Apple is exploring methods for such capabilities to inherit the caller’s isolation context, probably lowering sendability errors and making adoption of Swift 6 way more easy.

So, ought to we undertake Swift 6?

For present initiatives, I like to recommend continuing cautiously. Keep on with Swift 5 language mode until:

• Your mission is small and manageable for migration.

• You’ve a powerful understanding of concurrency ideas and may decide to resolving sendability points.

New initiatives might be constructed with Swift 6 language mode from the beginning, however be ready for challenges, particularly when interacting with Apple’s frameworks, which can lack full concurrency assist.

In case you’re modularizing your codebase with Swift packages, I like to recommend utilizing Swift 6 language mode in your (new) packages, as packages usually have fewer dependencies on Apple’s frameworks and are simpler to adapt and you’ll have Swift 5 and Swift 6 modules in the identical mission.

On the brink of undertake Swift 6

Earlier than adopting Swift 6, make sure you perceive:

• Sendability and tips on how to resolve associated errors.

• Using actors and their influence on isolation and asynchronicity.

• Easy methods to navigate ambiguous compiler errors.

I cowl all of those matters and extra in my e-book, Sensible Swift Concurrency in addition to my workshops. You can too evaluation and examine Swift evolution proposals and discussion board discussions to get a superb sense of how Swift Concurrency works.

In case you’ve began adopting Swift 6 or determined to carry off, I’d love to listen to your experiences! Join with me on X, BlueSky, or Mastodon.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles