SwiftData fetch array only when i needed

I used Query(filter:sortBy:) and show them in the ListView.

When I change the property of the model, because I fetched filtered and sorted array, the model immediately reflect the change and find its position.

What I want is at initializing it fetches filtered and sorted array. And when I change the property nothing happens. But when I tap on refresh button, then the array should change.

For example in ToDoList app, the array consists of not done works. when I tap done, it should stay until I refresh.

Is it possible?

Accepted Reply

You could have a var (tempVar) in the Query (non State var).

Keep the State var in the List.

Only update the State var from tempVar in Button action.

Replies

You could have a var (tempVar) in the Query (non State var).

Keep the State var in the List.

Only update the State var from tempVar in Button action.