Table - unable to use more than 10 columns

I've been trying to use the Table function as described in the session. When I try expanding the table beyond 10 columns the compiler hangs with the issue "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions." I've tried this in both the code provided in the session by replicating some of the given columns, and in other projects of my own. In all cases at adding the 11th column the same message is given.

Does anyone know if there is a limit to the column count? Or if a workaround exists?

Replies

Which version of Xcode do you use ?

Could you post the complete working (and crashing) code so that we can try to reproduce ?

May be a workaround (not very convenient) would be to create 2 Table ? In any case, that may be worth a bug report.

Note: your tags are confusing. Is it UIKit or SwiftUI (which is what I suppose). Not at all the same analysis.

  • Xcode is Version 13.0 beta 4 (13A5201i). OS is Monterey Version 12.0 Beta (21A5304g) Sorry about the tags - they were auto populated and this is my first post so I was a little confused. Yes - SwitfUI. I tried a simplistic side by side table approach - might work if I could figure out how to synchronize scrolling. Here's the code... I'm sure there is a better way to post it but couldn't find that quickly in forum FAQs.

    import SwiftUI @available(macOS 12.0, *) @main struct TablePlayApp: App {     var body: some Scene {         WindowGroup {             ContentView()         }     } } import SwiftUI @available(macOS 12.0, *) struct ContentView: View {   @State private var data = MyData.viewData

      var body: some View {

        Table(data) {

            TableColumn("One", value: .one)         TableColumn("Two", value: .two)         TableColumn("Three", value: .three)         TableColumn("Four", value: .four)         TableColumn("Five", value: .five)         TableColumn("Six", value: .six)         TableColumn("Seven", value: .seven)         TableColumn("Eight", value: .eight)         TableColumn("Nine", value: .nine)         TableColumn("Ten", value: .ten)

            // adding the next line will cause the compiler to give the message: 'The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions' at the 'var body: some View {' line. Using Group to break things up gives the same message.         //TableColumn("Eleven", value: .eleven)         //TableColumn("Twelve", value: .twelve)

        }   } }

    struct MyData {     static var viewData:[MyRowData] = [MyRowData(),MyRowData()] }

    struct MyRowData: Identifiable {     var id = UUID()     var one = "one"     var two = "two"     var three = "three"     var four = "four"     var five = "five"     var six = "six"     var seven = "seven"     var eight = "eight"     var nine = "nine"     var ten = "ten"     var eleven = "eleven"     var twelve = "twelve"

        var bool = false }

    @available(macOS 12.0, *) struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } }

  • Well that looks terrible.... if you see what I see after clicking submit which is a jumbled mess without breaks. How do I cleanly post code?

Add a Comment

I would suspect it has to do with the same limitation all of SwiftUI suffers: You can only declare 10 subviews inside of a view. The usual workaround is to use Group{} like this:

HStack{
    Group{
        Item1
        Item2
        ...
        Item10
    }
    Group{
        Item11
        ...
        Item 20
    }
}
  • I hadn't thought of that limitation when experimenting earlier. I tried using Group around subsets of TableColumns to keep the total below ten. The compiler didn't like the use of Group within the Table {} range. Even a small group would result in the same error message "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions."

Add a Comment