Post

Replies

Boosts

Views

Activity

Reply to SectionedFetchRequest not updating order of Sections
Just came across this looking for info on @SectionedFetchRequest. Better late than never 😛. See the accepted answer here: SwiftUI List not updating when core data property is updated in other view. This is a kludge of sorts, but a clever one that only adds two lines of code to fix the problem - no need for your workaround. SwiftUI updates the view when the view state changes, and you are changing the core data in view but with nothing to notify the view of the changes. The refreshID does that, causing the view to refresh when a swap is executed. I consider this Apple's bug. The whole point of using @FetchRequest and @SectionedFetchRequest is make Core Data objects 'published' so they can be observed in view - but as you show quite clearly it doesn't work properly. IMHO any change to the underlying data in Core Data should force the view to update automatically. One thing that occurred to me as I wrote this - maybe putting all the swap/reset, fetches etc in a VM than publishing from there would work (not sure, and I don't have time to try it), but that defeats the purpose of @FetchRequest and @SectionedFetchRequest.
Oct ’21