You can speed up a copy and paste the code from the project. The price is going to be $18 and the image name is hat01.png. So title is going to be Devslopes Logo Graphic Beanie. So we've got these hats and hoodies and things like that, and I'm just going to make the prices up and everything and so just follow along and let's make some data. So I'm getting this information from our merchandise images. So it's going to be a product and then it's going to ask for certain things like title, price, etc. Private let hat equals and we're just like we did up here with categories, we're going to create some products. So what we're going to do and we'll start off with hats just for fun. So what we're going to do is create a few different variables here for those products. Let's just put a space here for good measure and let's go to our services now and what we want to do is we want to create a service that allows us to get whatever product that we need and we know that we have hats, hoodies, etc, etc, etc. Price of type string, image name of type string, and then just like we did before on the categories self.title equals title, self.price equals the price, and self.imageName equals image name. Let's create our initializer and just press enter on the auto-complete there and we're going to say title of type string. So public var image name like we've done before as well too of type string. So a string is completely appropriate, and it'll become a string at one point anyway when you have to display in the text field. Why am I making a string instead of a dollar sign? Well, we're not actually using those numbers for anything except the display and when you make a purchase, they would probably happen on the backend anyway. So private set public var and we're going to say title type String, private set public var, a price. What we're going to do is just like we did with the category, we're going to have the data that we need, create some variables, initializer, things like that. Always use a struct unless you absolutely need a class, and that's the rule of thumb so let's make a struct. You can have multiple products just like you can have multiple categories and we'll make this a struct as well. We're going to create a new file and we're going to call this a Swift File here and we're going to call this a Product. So what we're going to do is we're going to go into our model folder here. The reason why I like to some nice build UI and go into the data before I actually maybe work in the view controller is because sometimes you can't move forward without data or you can build it your view controllers but how do I pass data from one screen to the other if it doesn't even exist and how can I show data on the cell even if it doesn't exist. The UI for it at least, and I think what we need to do now is start building out some of our data, hard-coded data in the app, as well as our data model and that we're going to need to host that data. So far, we have the Collection View cell in place from the last video. Welcome back ladies and gentlemen, and we're going to continue building our Coder Swag app.
0 Comments
Leave a Reply. |