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

Refined actor initialization and deinitialization

Available from Swift 5.10

Paul Hudson      @twostraws

SE-0327 adds some clarifications about how state inside actors is created and destroyed, and also relaxes some rules that were overly restrictive.

This proposal contains a number of small, specific changes to actors. For example, Swift will now automatically make actors with an async initializer move to the actor's executor when all its properties are initialized.

In code, it means the two print() calls shown below might execute on entirely different threads:

actor Actor {
    var name: String

    init(name: String) async {
        self.name = name

let actor = await Actor(name: "Margot")

This means the code has a potential suspension directly after the name property is set.

Save 50% in my WWDC sale.

SAVE 50% To celebrate WWDC24, 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!

Other changes in Swift 5.10…

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

Browse changes in all Swift versions

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.