SwiftUI async MainActor state
A SwiftUI order list ViewModel calls an async API and then changes the screen state with the result. Under Swift 6 strict concurrency, which part of this ViewModel would you isolate with @MainActor?
A SwiftUI order list ViewModel calls an async API and then changes the screen state with the result. Under Swift 6 strict concurrency, which part of this ViewModel would you isolate with @MainActor?
Put @MainActor on the whole ViewModel class (the @Observable type) rather than picking a few properties. The screen state properties and the methods that change them then all run on the main actor only; the network call hands off to another executor with await and resumes on main when the response arrives, so changing state after that is safe.
ConcurrencyShort answerIntro
A new iOS feature needs a network result shared across several screens, and the UI has to…
#mainactor #async-await
SwiftUIShort answerIntro
How is the way SwiftUI draws the screen fundamentally different from UIKit?
#swiftui
SwiftUIShort answerAdvanced
If you apply MVVM to a screen in a SwiftUI app that supports iOS 17 and later, how do you…
#mainactor
SwiftUIMultiple choiceBasics
Select all the correct statements about how ObservableObject's @Published updates SwiftUI…
#mainactor