You can bind the table to the fetch request's sort descriptors there is no need to have additional state, e.g. Table(stats, sortOrder: $stats.sortDescriptors) { When the users clicks on a table column the fetch and the table will update automatically. Unfortunately there is an issue where if the View containing the FetchRequest is re-init then the sortDescriptors get reset to their default. I'm not sure if that is a design flaw in @FetchRequest or we are supposed to make our own @State for the sort in the view above and pass it in as a binding and use the value in the @FetchRequest and using the binding to the binding in the Table, e.g. @Binding var sortDescriptors: [SortDescriptor] init(sd: Binding<[SortDescriptor]>) { _items = FetchRequest(sortDescriptors: sd.wrappedValue) _sortDescriptors = sd } ... Table(stats, sortOrder: $sortDescriptors) {
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: