
SwiftUI Cookbook
By :

The SwiftUI ActionSheet
and Alert
views are both used to request additional information from the user by interrupting the normal flow of the app to display a message. ActionSheet
provides the user with additional choices related to an action they are currently taking, whereas the Alert
view informs the user if something unexpected happens or they are about to perform an irreversible action.
In this recipe, we will create an action sheet that gets displayed when the user taps some text in the view.
Create a SwiftUI app named PresentingActionSheet
.
We will implement an action sheet by adding a .actionSheet()
modifier to a view as well as a trigger that changes the value of a variable used to determine if the sheet is shown or not. The steps are as follows:
ContentView
struct but above the body
variable, add an @State
variable to store the state of the action sheet:@State private var showSheet =...