Skip to content

Instantly share code, notes, and snippets.

@4brunu
Created September 23, 2021 14:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4brunu/d75d9bd7f62d95f0b4830d3c56eb3c61 to your computer and use it in GitHub Desktop.
Save 4brunu/d75d9bd7f62d95f0b4830d3c56eb3c61 to your computer and use it in GitHub Desktop.
SwiftUI - show multiple alerts
struct BlankView: View {
var body: some View {
Text("")
.frame(width: 0, height: 0)
.hidden()
}
}
struct MyScreenView: View {
var body: some View {
// loading alert
BlankView()
.alert(isPresented: $showLoadingAlert, content: {
Alert(title: Text("Logging in"))
})
// error alert
BlankView()
.alert(isPresented: $showErrorAlert, content: {
Alert(title: Text("Wrong passcode"), message: Text("Enter again"), dismissButton: .default(Text("Confirm")))
})
VStack {
// Your View content
...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment