With Swift 6.2, Apple has made a a number of enhancements to Swift Concurrency and its approachability. One of many largest modifications 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 straightforward to by accident introduce a great deal of concurrency in your apps.
On this put up I would wish to take a fast take 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.
New tasks can have this set to MainActor whereas present tasks can have this set to nonisolated
. I extremely advocate attempting to set this to MainActor as a substitute. You will have to refactor a few of your code and apply specific nonisolated
declarations the place you meant to make use of concurrency so you will need 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 by way of Swift 6.2 is nonisolated(nonsending)
. This function makes it in order that your nonisolated sync capabilities routinely inherit the calling actor’s isolation as a substitute of at all times working on the worldwide executor with out being remoted to any actor. To get the outdated conduct again you possibly can annotate your capabilities with @concurrent
. You’ll be able to be taught extra about this in my put up about Swift 6.2’s modifications.
You’ll be able to activate nonisolated(nonsending)
in one in all two methods. You’ll be able to both allow the function flag for this function or you possibly can activate “Approachable Concurrency”.
WIth Approachable Concurrency you’ll get nonisolated(nonsending)
together with a few different modifications that ought to make the compiler smarter and extra wise in the case of how concurrent your code will actually be.
When you’re undecided which one it’s best to use I like to recommend that you just go for Approachable Concurrency.