SwiftUI Table on macOS with two columns. In some test code the items being sorted are:
@Observable
final class Item: Identifiable {
let id: Int
var displayId: String {
String(id)
}
let description: String
init(_ id: Int) {
self.id = id
self.description = UUID().uuidString
}
}
The table columns are displayId
and description
. The Tables initial sort order is defined by this descriptor:
var sortOrder = [KeyPathComparator(\Item.description)]
The strangeness is this: the sorted description order is very strange.
"0B5..." sorts before "0B0..." ? Or if I reverse the sort order I get this:
"AA..." before "FF..."
What am I missing? Sorting the first column does what I'd consider to be the right thing, showing the column in numerical order even though I'm using the String representation of id
.