Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Table - dynamic columns

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 ?? "")
        })
    }
}
like image 829
Balázs Avatar asked Oct 24 '25 07:10

Balázs


1 Answers

Apparently it is now possible. Have not tested myself, but the latest apple sdks include:

TableColumnBuilder and TableColumnForEach

like image 87
Baxter Lopez Avatar answered Oct 26 '25 22:10

Baxter Lopez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!