Skip to content

Instantly share code, notes, and snippets.

@xremix
Created April 2, 2023 12:53
Show Gist options
  • Save xremix/c6a4e476649d226bf46c3b63f62befd4 to your computer and use it in GitHub Desktop.
Save xremix/c6a4e476649d226bf46c3b63f62befd4 to your computer and use it in GitHub Desktop.
Alerts in SwiftUI
struct ContentView: View {
@State private var presentAlert = false
@State private var username: String = ""
@State private var password: String = ""
var body: some View {
Button("Show Alert") {
presentAlert = true
}
.alert("Login", isPresented: $presentAlert, actions: {
TextField("Username", text: $username)
SecureField("Password", text: $password)
Button("Login", action: {})
Button("Cancel", role: .cancel, action: {})
}, message: {
Text("Please enter your username and password.")
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment