Alert provides a pop up that appears in the center of the device which could either contain message with button that will trigger based on your need or message and a button that acknowledge the message. Either way, it should work to fit your need.
A container for an alert presentation.
Apple Documentation
In this tutorial, you’ll learn what is alert in SwiftUI. You’ll learn:
- How to create an alert
Prerequisites
To follow along this tutorial, you’ll need some basic knowledge in:
- A basic familiarity with Swift.
- At least Xcode 11
Alert
Using a flag to determine whether the alert is shown or not.
1 |
@State private var alertShown = false |
Here, you will be using a button that will trigger an alert.
1 2 3 4 5 |
Button("Show Alert") { self.alertShown = true }.alert(isPresented: $alertShown) { () -> Alert in Alert(title: Text("Alert Title"), message: Text("Alert Message"), dismissButton: .default(Text("Ok"))) } |
With the code above, by clicking on the button, an alert will then pop up. You may configure the title, message and button. For the current configuration, only 1 button is configure.

If there is a need for more than one button, you may configure to your need.
1 |
Alert(title: Text("Alert Title"), message: Text("Alert Message"), primaryButton: .default(Text("Ok")), secondaryButton: .default(Text("Cancel"))) |

Where to go From Here
If you feel like you are ready to take on more challenges, feel free to check out some other tutorials that we have created:
The problem here is that one must click a button to display the alert. What if I want to display the alert programmatically when some event happens. for example, I discover a Bluetooth device? The alert tells the user info about the device and asks if a connection is desired, If a YES is clicked, a BLuetooth method is called to connect to the device.