SwiftUI API loading state
A SwiftUI list screen loads data from a hotel API. To handle loading, success, no results, and error on screen without missing one, how would you model the state?
A SwiftUI list screen loads data from a hotel API. To handle loading, success, no results, and error on screen without missing one, how would you model the state?
Keep one state enum with loading, success, empty, and error cases as the screen state. Drawing the four screens with a switch in body lets the compiler catch a missing case, and empty results are distinguished from success. Attach the request with .task so it's canceled automatically when the screen goes away.
SwiftUIShort answerIntro
How is the way SwiftUI draws the screen fundamentally different from UIKit?
#swiftui
SwiftUIShort answerBasics
SwiftUI views have no viewDidLoad or viewWillAppear like UIKit. How does a view actually…
#task
SwiftUIMultiple choiceAdvanced
In a SwiftUI view that loads data, what's the correct statement about how these two…
#task
SwiftUIShort answerBasics
In a SwiftUI product editing screen, the parent view owns the product model and a child…
#swiftui