I have two main models, House and Expense. On the home page I show a list of the three most recent expenses using the following query:
var descriptor = FetchDescriptor<Expense>(predicate: #Predicate { $0.houseID == house.id }, sortBy: [SortDescriptor(\.date, order: .reverse)])
descriptor.fetchLimit = 3
_recentExpenses = Query(descriptor)
I have a NavigationLink that takes you to the full list of expenses:
NavigationLink {
ExpenseListView(house: house)
} label: {
Text("See all")
}
On this page I have a query similar to the previous one, without the fetch limit:
let descriptor = FetchDescriptor<Expense>(
predicate: #Predicate { $0.houseID == house.id}
)
_expenses = Query(descriptor)
The problem is that when I click on the navigation link to go to the expenses page, the app freezes.
I tried passing the expenses array to the second page instead of invoking another query, but this way the view doesn't update when I update the expenses.
Is there a way to solve this problem? Or a way to pass a Binding of the fetched results?