SwiftUI: Alert, Action Sheet

Tram Ho

A container for an alert presentation.

Apple Documentation.

In this tutorial, you will learn about alert in SwiftUI:

  • How to create an alert

Prerequisites

To follow along with this tutorial, you’ll need some basic knowledge about:

  • Basic with Swift.
  • Xcode 11 and above

Alert

Use the flag to determine if the alert is displayed.

Here, you will use a button to activate the alert.

With the above code, when the button is clicked, an alert will pop up. You can customize the subject, message and button. Currently, only 1 button is configured.

If you need more than one button, you can.

Action Sheet

You will use a flag to determine if the action sheet is displayed or not. You create a bool variable to keep state.

Next, create a button below. And when the action sheet is activated, you change the flag’s state to true.

Next, you create the action sheet as follows:

The result will look like this:

Thank you everyone for following up here. Thanks !!

Share the news now

Source : Viblo