From the course: Complete Guide to SwiftUI
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Solution: Add a button
From the course: Complete Guide to SwiftUI
Solution: Add a button
(upbeat music) - [Instructor] Okay, there's lots of ways of doing this one, but here's one with a few tricks that I tend to use. First of all, we're going to make a state variable, and we're going to do that over here in a menu item view. So go over here. And above the body, you'll put a state variable, making sure you put private in there. And I'm going to call it Added Item. And my way of doing this will be just to add a flag to do with this. Okay now, inside of this, we're going to now start making our button, and the button is going to go, in this case we got a V stack. I'm going to close up some of my other stacks here so I can see where I am. Here's this stack here, and I'm going to try to put it underneath this stack all the way at the bottom of the V stacks we've got. So it'll always be on the bottom here. And I'll start with button. And we're going to do the action first here. So I'm going to hit return.…
Contents
-
-
-
-
-
- (Locked) MVC vs. MVVM4m 19s
- (Locked) State variables and buttons3m 57s
- (Locked) Challenge: Add a button45s
- (Locked) Solution: Add a button3m 50s
- (Locked) Use Binding variables10m 10s
- (Locked) The Identifiable protocol5m 13s
- (Locked) Add a model to root views6m 47s
- Populating collections with List4m 45s
- (Locked) Selection and binding variables6m 29s
- (Locked)
-
-
-
-
-
-
-
-
-
-
-
-