From the course: SwiftData Essential Training

Unlock this course with a free trial

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

Solution: Ratings

Solution: Ratings

- [Instructor] I'll start in the enum ratings icon for the solution. So let's go ahead and close up this and let's go with enumerations and we see RatingsIcon and that's got to be codeable. That's the first thing we got to change. Next we're going to look at the model itself, which is RatingModel, and RatingModel does not have a rating icon in it. So let's do a var ratingIcon and we'll make that and then add it to initializer And we'll default it to a star. And then put inside here self.ratingIcon equal ratingIcon. All right, so now we've set up our initializer on our model, so we can now go into ratings list view and start working from there. I'm going to add an extra state variable. We'll make that state private var, make it a ratingIcon, and that will be of type RatingsIcon, and I'm going to make that one of the ones we got. We have circle, heart, plate, and star, and we've been using star, so that'll be my default will be star, and anything that needs it elsewhere, we'll use a…

Contents