Update for macOS 12+ (Monterey)
In macOS Monterey, NSTableView can now be wrapped with Table. In addition, Table can support TableColumns with key paths and trailing closures.
struct ContentView: View {
@State private var characters = StoryCharacter.previewData
var body: some View {
Table(characters) {
TableColumn("🛠") { CharacterIcon($0) }
.width(20)
TableColumn("Villain") { Text($0.isVillain ? "Villain" : "Hero") }
.width(40)
TableColumn("Name", value: \.name)
TableColumn("Powers", value: \.powers)
}
}
}