Last active
May 25, 2020 17:42
-
-
Save archieedwards/47fe63d6f56e0d67f21f470ce910548b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State var alertItem : AlertItem? | |
var body: some View { | |
/// button | |
Button(action: { | |
self.alertItem = AlertItem(title: Text("I'm an alert"), message: Text("Are you sure about this?"), primaryButton: .default(Text("Yes"), action: { | |
/// trigger second alert | |
DispatchQueue.main.async { | |
self.alertItem = AlertItem(title: Text("Error"), message: Text("An unexpected error occurred"), dismissButton: .default(Text("OK"))) | |
} | |
}), secondaryButton: .cancel()) | |
}, label: { | |
Text("SHOW ALERT") | |
}).alert(item: $alertItem) { alertItem in | |
guard let primaryButton = alertItem.primaryButton, let secondaryButton = alertItem.secondaryButton else{ | |
return Alert(title: alertItem.title, message: alertItem.message, dismissButton: alertItem.dismissButton) | |
} | |
return Alert(title: alertItem.title, message: alertItem.message, primaryButton: primaryButton, secondaryButton: secondaryButton) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment