HomeiOS Developmentnonisolated Execution Variations Earlier than and After Xcode 26.2

nonisolated Execution Variations Earlier than and After Xcode 26.2


I’ve an older mission that was created earlier than Xcode 26.2.

In Xcode variations previous to 26.2, there was no Swift Compiler – Concurrency construct setting.

nonisolated Execution Variations Earlier than and After Xcode 26.2

With these older variations, the next habits happens: a nonisolated perform executes off the principle thread.

class ViewController: UIViewController {

    override func viewDidLoad() {
        tremendous.viewDidLoad()
        run()
    }

    personal func run() {
        Activity {
            await runInMainThread()
        }
    }
    
    func runInMainThread() async {
        print(">>>> IN runInMainThread(), Thread.isMainThread (Thread.isMainThread)")
        await runInBackgroundThread()
    }
    
    personal nonisolated func runInBackgroundThread() async {
        print(">>>> IN runInBackgroundThread(), Thread.isMainThread (Thread.isMainThread)")
    }
}

Output:

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

Nonetheless, beginning with Xcode 26.2, Apple launched the Swift Compiler – Concurrency settings.

enter image description here

When working the identical code with the default configuration:

Approachable Concurrency = Sure
Default Actor Isolation = MainActor

That is the output

Output:

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

the nonisolated perform now executes on the major thread.

This raises the next questions:

  1. What’s the right Swift Compiler – Concurrency configuration if I need a nonisolated perform to run off the principle thread?

  2. Is nonisolated nonetheless an applicable manner to make sure code runs on a background thread?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments