Created
May 25, 2020 17:28
-
-
Save archieedwards/cdde648c441ac047fffcabcd3ce49fb0 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 { | |
VStack{ | |
/// button 1 | |
Button(action: { | |
self.alertItem = AlertItem(title: Text("I'm an alert"), message: Text("Are you sure about this?"), primaryButton: .default(Text("Yes"), action: { | |
/// insert alert 1 action here | |
}), secondaryButton: .cancel()) | |
}, label: { | |
Text("SHOW ALERT 1") | |
}) | |
/// button 2 | |
Button(action: { | |
self.alertItem = AlertItem(title: Text("I'm another alert"), dismissButton: .default(Text("OK"))) | |
}, label: { | |
Text("SHOW ALERT 2") | |
}) | |
}.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