Question 1 : I want to be able to sort by all the columns. How many KeyPathComparators should be in the sortOrder array? Surprisingly, a single comparator works for all columns . Question 2: What is the value of newOrder? Is it same as the sortOrder? What does it contain? You get the same behaviour with this: .onChange(of: sortOrder) { _ in people.sort(using: sortOrder) } . Question 3: sortOrder contains the comparator for only givenName. How does the above code able to provide sort functionality for all the columns? Same as question 1 ? I found this tutorial interesting. https://www.kodeco.com/books/macos-by-tutorials/v1.0/chapters/4-using-tables-custom-views And changed your code to make it work better (immediately change rows when tapping another column header) struct Person: Identifiable { let givenName: String let familyName: String let emailAddress: String let id = UUID() } private var people = [ Person(givenName: f1, familyName: Bob, emailAddress: xbob@ example.com),
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: