I am fairly new to swift and swiftui, trying to build a csv reader macOS application.
I was just wondering if there is a way to render a SwiftUI Table with dynamic Columns - there is no was to know the number of columns at build time.
I can't find any resource about this.
I have tried the following structure but it doesn't work, as the columns aren't hardcoded.
Table(viewModel.rows, selection: $selection) {
ForEach(viewModel.columns, id: \.self) { column in
TableColumn(column, value: { row in
Text(row[column] as? String ?? "")
})
}
}
Apparently it is now possible. Have not tested myself, but the latest apple sdks include:
TableColumnBuilder and TableColumnForEach
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With