Using @Query allows you to access the model class from your SwiftUI view, it allows you to specify sorting, filtering, etc, by using computed properties.
In the ViewModel, you can define (assuming your model is called Todo):
var todos: Todo
If Todo has some properties like title, isCompleted, etc.
declare variables in your view model as:
var title: String {
todo.title
}
var isCompleted: Bool {
todo.isCompleted
}
Then you can do your logic in your SwiftUI view that has declared the view model to call viewModel.isCompleted. But if you modify the view model properties, they will not be persisted until you define it back, e.g.:
// E.g.
todo.isCompleted = true
todo.title = viewModel.title
try? context.save()