nonisolated Execution Differences Before and After Xcode 26.2

2 weeks ago 16
ARTICLE AD BOX

I have an older project that was created before Xcode 26.2.

In Xcode versions prior to 26.2, there was no Swift Compiler – Concurrency build setting.

enter image description here

With those older versions, the following behavior occurs: a nonisolated function executes off the main thread.

class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() run() } private func run() { Task { await runInMainThread() } } func runInMainThread() async { print(">>>> IN runInMainThread(), Thread.isMainThread \(Thread.isMainThread)") await runInBackgroundThread() } private nonisolated func runInBackgroundThread() async { print(">>>> IN runInBackgroundThread(), Thread.isMainThread \(Thread.isMainThread)") } }

Output:

>>>> IN runInMainThread(), Thread.isMainThread true >>>> IN runInBackgroundThread(), Thread.isMainThread false

However, starting with Xcode 26.2, Apple introduced the Swift Compiler – Concurrency settings.

enter image description here

When running the same code with the default configuration:

Approachable Concurrency = Yes Default Actor Isolation = MainActor

This is the output

Output:

>>>> IN runInMainThread(), Thread.isMainThread true >>>> IN runInBackgroundThread(), Thread.isMainThread true

the nonisolated function now executes on the main thread.

This raises the following questions:

What is the correct Swift Compiler – Concurrency configuration if I want a nonisolated function to run off the main thread?

Is nonisolated still an appropriate way to ensure code runs on a background thread?

Read Entire Article