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.

Fetch data

Fetch data

- [Instructor] There's one small problem with query, which we could see right here, and that is that this query can't change the requests of a sorted filter since they happen within a property declaration. So we're going to try some things here. And first of all, I want to try to move these predicates and sort descriptors in. So I'm just going to Command + X those and then let's just pop them right above the environment variable here with a Command + V and paste them in. And you can start seeing that it's already giving you errors here. So I'm go pull up the errors on the side here. And you see that we've got all kinds of things going on. It's just not going to work in this situation. So we're going to have to do something else with this query if we wanted to bring these into the view, or if we wanted to dynamically use them and switch between those. So we'd switch between stars and pizzas or great in all ratings. And we do that with the modelContext fetch method. So first I'm going…

Contents