I have a rather info dense SwiftUI Table that has > 10 columns. If all the columns are simple Text() views, I can group them to get past the constructor constraint of 10 items only.
But if I have one column is a TextField (thus with a binding) it compiles/works great up to 10 columns. When I try to Group {} less than 10 columns or add more than 10 columns with a subset in Group {}, I get Generic parameter 'R' could not be inferred
Here is some minimal viable code that reproduces the issue. If I uncomment out the Group {
I get a compile error:
struct ContentView: View {
@State var selection = Set<TestStruct.ID>()
@StateObject var viewModel = ViewModel()
var body: some View {
VStack {
Table($viewModel.data, selection: $selection) {
// Group {
TableColumn("Col") { $item in
TextField("Placeholder", text: $item.text)
}
TableColumn("Data") { $item in
Text("\(item.data)")
}
TableColumn("D3") { $item in
Text("\(item.d3)")
}
TableColumn("D4") { $item in
Text("\(item.d4)")
}
TableColumn("D5") { $item in
Text("\(item.d5)")
}
TableColumn("D6") { $item in
Text("\(item.d6)")
}
TableColumn("D7") { $item in
Text("\(item.d7)")
}
TableColumn("D8") { $item in
Text("\(item.d8)")
}
TableColumn("D9") { $item in
Text("\(item.d9)")
}
TableColumn("D10") { $item in
Text("\(item.d10)")
}
// TableColumn("D11") { $item in
// Text("\(item.d11)")
// }
// }
}
}
}
class ViewModel : ObservableObject {
struct ContainedTestStruct: Identifiable {
var id = UUID()
var text: String
var data: Double
var d3: String
var d4: String
var d5: String
var d6: String
var d7: String
var d8: String
var d9: String
var d10: String
var d11: String
}
@Published var data =
[ContainedTestStruct(text: "Test", data: 3.141, d3: "d3", d4: "d4", d5: "d5", d6: "d6", d7: "d7", d8: "d8", d9: "d9", d10: "d10", d11: "d11"),
ContainedTestStruct(text: "editable", data: 2.71828183, d3: "d3", d4: "d4", d5: "d5", d6: "d6", d7: "d7", d8: "d8", d9: "d9", d10: "d10", d11: "d11"),
ContainedTestStruct(text: "FooBar", data: 42.0, d3: "d3", d4: "d4", d5: "d5", d6: "d6", d7: "d7", d8: "d8", d9: "d9", d10: "d10", d11: "d11")]
}
Is there a way to have both >10 columns and have some of them be editable?