async/await in SwiftUI | raywenderlich.com

Convert a SwiftUI app to use the new Swift concurrency and find out what’s going on beneath the shiny surface.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/25013447-async-await-in-swiftui

i didn’t know how to get rid of that irritating fix until this awesome tutorial, thank you!

Don’t click any of the Fix buttons! Go to the target page and change Deployment Info from iOS 14.0 to iOS 15.0

1 Like

Hi Audrey - Thanks for the tutorial. I’ve gotten to the part where we’re looking at fetchJoke running on the MainActor thread. I’m using a nightly toolchain from 2022-04-23, which has the updated Task syntax:

                Button {
                    Task {
                      try? await jokeService.fetchJoke()
                    }
                } label: { ...

Instead of running on Thread 1, its running on Thread 4:
image

Any thoughts as to why it’s no longer running on the main thread? Am I missing something? TIA

And if only I had kept reading, I would’ve seen your note:

Note : This seems to be a fluke. The Explore structured concurrency in Swift video says a detached task inherits nothing from its origin, so it shouldn’t inherit the MainActor thread. A future Xcode beta might enforce this.

Well, it appears that this toolchain now enforces that!

1 Like