I habe the following code :
@Environment(\.managedObjectContext) private var context
@FetchRequest(fetchRequest: Club.fetch(NSPredicate.all)) private var clubs: FetchedResults<Club>
@State private var selectedClubs = Set<Club.ID>()
@State var sortOrder: [KeyPathComparator<Club>] = [
.init(\.city, order: SortOrder.forward)
]
var body: some View {
VStack {
Text("Clubs")
Table(clubs, selection: $selectedClubs, sortOrder: $sortOrder) {
TableColumn("Club ID", value: \.clubId)
TableColumn("Name", value: \.name)
TableColumn("Short Name", value: \.shortName)
TableColumn("Acronym", value: \.acronym)
TableColumn("City", value: \.city)
}.onChange(of: sortOrder) { newValue in
print(newValue)
}
}
}
}
How can I enable column sorting? The example app from wwdc does not use Core Data.