From the course: SwiftData Essential Training
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Solution: Sort and search names - Swift Tutorial
From the course: SwiftData Essential Training
Solution: Sort and search names
- [Instructor] All right, so here's my solution to this. So let's go back over here and I'm going to go into names again and we'll go to names list view and up to the top. And again, we'll switch over these two. So we'll do a command slash here and a command slash up here. And that'll get me back to a state for the name model. And then I'm going to make a function in the struct. Let's put it just before the body here because I've got an add name there. So let's put fetch names in here, func fetchNames, like that. And then inside of that we're going to want all records, so I can skip the predicate 'cause it's going to want all the records, and that'll just leave it alone. I don't need to put an all. I'm going to sort this by name, using the ternary conditional operator for the sort direction. So we've got a sort direction here. If you look up here that is is sorting up true is going to be the state variable that I'm using for this, and you can see it down here in the button. We'll find…