Beginning Networking with URLSession, Episode 12: Handle Errors | Kodeco


This is a companion discussion topic for the original entry at https://www.kodeco.com/28450876-beginning-networking-with-urlsession/lessons/12

I’m wondering if it’s really necessary to use the @MainActor property wrapper for @State properties in SwiftUI views. Doesn’t code inside view execute on the main thread by default? Or do we need to explicitly ensure that code inside a view executes on the main thread?

View code executes on the main thread by default unless you were to add a background Task in there.

You likely won’t run into problems if you try to call an async method because the compiler should show a warning or error as you are trying to call and async method from a non-async context.

Worst-case scenario try to enable the thread sanitizer and leverage Instruments to check your threads :slight_smile: