Setting default actor isolation in Xcode 26 – Donny Wals

0
1
Setting default actor isolation in Xcode 26 – Donny Wals


With Swift 6.2, Apple has made a a number of enhancements to Swift Concurrency and its approachability. One of many largest adjustments is that new Xcode tasks will now, by default, apply an implicit most important actor annotation to all of your code. This primarily makes your apps single-threaded by default.

I actually like this modification as a result of with out this modification it was far too simple to unintentionally introduce a great deal of concurrency in your apps.

On this publish I might wish to take a fast have a look at how one can management this setting in addition to the setting for nonisolated(nonsending) from Xcode 26’s construct settings menu.

Setting your default actor isolation

Open your construct settings and search for “Default Actor Isolation”. You should use the search function to make it simpler to search out the setting.

Setting default actor isolation in Xcode 26 – Donny Wals

New tasks can have this set to MainActor whereas present tasks can have this set to nonisolated. I extremely advocate making an attempt to set this to MainActor as an alternative. You will have to refactor a few of your code and apply express nonisolated declarations the place you meant to make use of concurrency so you will wish to allocate a while for this.

MainActor and nonisolated are the one two legitimate values for this setting.

Enabling nonisolated(nonsending)

One other function that is launched via Swift 6.2 is nonisolated(nonsending). This function makes it in order that your nonisolated sync features mechanically inherit the calling actor’s isolation as an alternative of at all times working on the worldwide executor with out being remoted to any actor. To get the outdated conduct again you may annotate your features with @concurrent. You’ll be able to be taught extra about this in my publish about Swift 6.2’s adjustments.

You’ll be able to activate nonisolated(nonsending) in one in every of two methods. You’ll be able to both allow the function flag for this function or you may activate “Approachable Concurrency”.

WIth Approachable Concurrency you’ll get nonisolated(nonsending) together with a few different adjustments that ought to make the compiler smarter and extra wise with regards to how concurrent your code will actually be.

For those who’re unsure which one you need to use I like to recommend that you just go for Approachable Concurrency.

LEAVE A REPLY

Please enter your comment!
Please enter your name here