I was wondering if ModelContext's fetch() contains an auto-updating results array? I ask because there is no documentation yet and in the WWDC23 lounge it was suggested by Debbie G to use fetch()
to overcome the limitations of @Query
i.e. no way to use dynamic filtering or sorting. I suppose we would call fetch()
from onAppear
and onChanged
to support dynamic queries that also have auto-updating of results. Personally I don't understand why @Query
and the old @FetchRequest
were implemented as property wrappers instead of SwiftUI modifiers, e.g. .fetch(predicate:sort:)
to match other modifiers like .task(id:)
.
I was hoping for it to behave similar to Date's formatted() that returns a locale-aware string that automatically invalidates SwiftUI Text
when the locale changes. Although I'm not exactly sure how it works.
If fetch()
doesn't auto-update then what would be the point of using it instead of just using NSFetchRequest
with dictionary result type to get data into a SwiftUI view struct fast and memory efficient.