12.2 C
Canberra
Friday, January 23, 2026

nonisolated Execution Variations Earlier than and After Xcode 26.2


I’ve an older venture 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 conduct happens: a nonisolated operate executes off the principle thread.

class ViewController: UIViewController {

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

    non-public func run() {
        Job {
            await runInMainThread()
        }
    }
    
    func runInMainThread() async {
        print(">>>> IN runInMainThread(), Thread.isMainThread (Thread.isMainThread)")
        await runInBackgroundThread()
    }
    
    non-public 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 operating 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 operate now executes on the principal thread.

This raises the next questions:

  1. What’s the right Swift Compiler – Concurrency configuration if I need a nonisolated operate 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

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles