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 })) }
truein a button on the alert; as soon as the button action closure is executed, SwiftUI will set it back tofalse.falseby SiwfUI and thentrueby 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.