BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

More concurrency changes

Available from Swift 5.6

Paul Hudson      @twostraws

Swift 5.5 added a lot of features around concurrency, and 5.6 continues the process of refining those features to make them safer and more consistent, while also working towards bigger, breaking changes coming in Swift 6.

The biggest change is SE-0337, which aims to provide a roadmap towards full, strict concurrency checking for our code. This is designed to be incremental: you can import whole modules using @preconcurrency to tell Swift the module was created without modern concurrency in mind; or you can mark individual classes, structs, properties, methods and more as @preconcurrency to be more selective.

In the short term this makes it significantly easier to migrate larger projects to modern concurrency.

Another area that’s changing is the use of actors, because as a result of SE-0327 Swift 5.6 now issues a warning if you attempt to instantiate a @MainActor property using @StateObject like this:

import SwiftUI

@MainActor class Settings: ObservableObject { }

struct OldContentView: View {
    @StateObject private var settings = Settings()

    var body: some View {
        Text("Hello, world!")

This warning will be upgraded to an error in Swift 6, so you should be prepared to move away from this code and use this instead:

struct NewContentView: View {
    @StateObject private var settings: Settings

    init() {
        _settings = StateObject(wrappedValue: Settings())

    var body: some View {
        Text("Hello, world!")
Save 50% in my Black Friday sale.

SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Other changes in Swift 5.6…

Download all Swift 5.6 changes as a playground Link to Swift 5.6 changes

Browse changes in all Swift versions

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.