Spot the bug
After a network error, the spinner never stops. Tap the line that causes it.
@MainActor @Observablefinal class LoadModel {var items: [Item] = []var isLoading = falsevar error: Error?func load() async {isLoading = truedo {items = try await API.items()isLoading = false} catch {self.error = error}}}
Hint 1 of 1
On which path does isLoading go back to false?
Choose an answer, then open Show answer below to check it.
Show answer
- Answer: line 10
isLoading = false
Line 10 resets the spinner only on success. On error the catch block never resets it. Put defer { isLoading = false } right after line 7, or use a single state enum.