From the course: Complete Guide to SwiftUI

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Alerts

Alerts

- [Instructor] Sometimes you need a short message or simple decision. For that, we use alerts. For example, I might prompt the user to confirm the purchase of a pizza, like is active in the symbol effects that start animations alerts present with a Boolean value. So let's go to menu item view to start this and go over here. And I'm going to add another state variable because we need this Boolean value. So let's put in here right under the private var. Let's put it there. And I'll put here a state variable. Make a private var and I'm going to call this present view. It's going to be a bool, and we'll start at false. All right, and now let's go scroll down into this, into the button code. And we got this button code right here. The first thing I want to do is when the user presses the button, I'm going to show the alert and I change here that value of present view. And then on the end of the button, which I'll put here,…

Contents