SwiftUI Alert setting presentation condition true in it's button action closure not showing the alert again

53 Views Asked by At

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
          }))
      }
0

There are 0 best solutions below