SwiftUI Table View with Array of reference types?

I am trying to use a SwiftUI Table View [1] with an Array of class objects so that updates to properties in the class objects are reflected in the table. This works fine for me with structs and @State, however, I'm trying to find a way to achieve the same effect with @StateObject given that @State only supports value types.

The only problem is that @StateObject doesn't seem to be supported by Array. When I try to extend Array to conform to ObservableObject, I get:

Non-class type 'Array<Element>' cannot conform to class protocol 'ObservableObject'

It seems that wrapping the array with an object and using @Published to publish changes does not work as evidenced by this [2] other post.

Appreciate if anyone has any ideas on how to make this work! And if there is no way to make it work, I don't understand why Apple has made it so that a TableColumn initializer would require [3] the RowValue to conform to NSObject. Because this effectively means that to have sorting capabilities for a column, the underlying data type for your Table needs to be a class!

[1] https://developer.apple.com/documentation/swiftui/table [2] https://developer.apple.com/forums/thread/134185?answerId=727605022#727605022 [3]

I didn't figure out the issue but was able to progress by using a different TableColumn initializer that didn't require my data type to inherit from NSObject. It would still be nice to understand how to solve the original issue.

SwiftUI Table View with Array of reference types?
 
 
Q