I have view model that keeps state around like so:
I did this to keep the model's loading state out of the view logic.
The idea is to disable the dialog and overlay a spinner. Like so:
The disable causes a cycle detected message. I actually get several of them. I don't want to move this code out of the model the model is managing some loading and knows what state it is in. If there is more to the loading then I want to be able to have the model mange the state.
The other idea is for this model to be reusable
Code Block Swift class FeedModel: ObservableObject { enum CurrenState: Equatable { case none case loading case error case done } private (set) var feed: RssFeed? @Published private (set) var currentState: CurrenState = .none
I did this to keep the model's loading state out of the view logic.
The idea is to disable the dialog and overlay a spinner. Like so:
Code Block swift ZStack { VStack(alignment:.leading) { Text("Enter a feed address") TextField("", text: $text) .frame(idealWidth: 300) HStack { Spacer() Button("Cancel") { isOpen = false } .keyboardShortcut(.cancelAction) Button("Add") { model.load(address: text) } .keyboardShortcut(.defaultAction) } } .padding() .disabled(model.currentState == .loading) if model.currentState == .loading { ProgressView() .progressViewStyle(CircularProgressViewStyle()) } }
The disable causes a cycle detected message. I actually get several of them. I don't want to move this code out of the model the model is managing some loading and knows what state it is in. If there is more to the loading then I want to be able to have the model mange the state.
The other idea is for this model to be reusable