1

So the thing I want to do is that I have an api call if it fails I show an alert with message, OK button and Retry Button.

Everything is working good but when I do retry it don't shows the alert again if it fails again and it's not showing alert again even if I am directly setting property which I am passing in isPresented as true by hard code in the closure by my self.

Here is the code.

.alert(isPresented: $viewModel.isErrorMessageVisible) { Alert( title: Text(StringsProvider.error), message: Text(viewModel.errorMessage), primaryButton: .default(Text(StringsProvider.ok), action: { // do nothing }), secondaryButton: .default(Text(StringsProvider.retry), action: { viewModel.isErrorMessageVisible = true })) } 
2
  • Your code doesn't make sense. You are trying to set the alert display binding to true in a button on the alert; as soon as the button action closure is executed, SwiftUI will set it back to false. Commented Nov 17, 2023 at 19:40
  • @Paulw11, I agree with you that SwiftUI will set it false. Saw that being done in debugger as well. But if I am setting it true then shouldn't it be visible again? In debug logs first it get's set false by SiwfUI and then true by the code in action closure. I presented it this way to make it look readable and making debugging easy. In actuality API gets called and then error should be shown. Commented Nov 18, 2023 at 4:15

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.