SwiftUI MacOS TableColumn compiler can't type-check expression in reasonable time.

This compiles:

Table(sortedTableData, selection: $selectedLongCallID, sortOrder: $sortOrder) {
        Group {
          TableColumn("Description", value: \LongCall.description) { Text($0.description) }.width(min: 200)
          TableColumn("Qty", value: \LongCall.quantity) { Text("\($0.quantity)") }.width(min: 40)
        }
        Group {
          TableColumn("Open Date", value: \LongCall.openDate) { Text($0.openDate.prettyDate()) }.width(min: 75)
          TableColumn("Days Held", value: \LongCall.daysHeld) { Text("\($0.daysHeld)") }
        }
        Group {
          TableColumn("Exp Date", value: \LongCall.expirationDate) { Text($0.expirationDate.prettyDate()) }.width(min: 75)
          TableColumn("Days til Exp", value: \LongCall.daysTilExpiration) { Text("\($0.daysTilExpiration)") }
        }
        Group {
          TableColumn("Debit Per Contract", value: \LongCall.openingDebitPerContract) { Text($0.openingDebitPerContract.formatToCurrency()) }
          TableColumn("Total Debit", value: \LongCall.totalDebit) { Text($0.totalDebit.formatToCurrency()) }
        }
        Group {
          TableColumn("Break Even Price", value: \LongCall.breakEvenPrice) { Text($0.breakEvenPrice.formatToCurrency()) }
          TableColumn("Target Profit %", value: \LongCall.targetProfitPercentageDisplay) { Text($0.targetProfitPercentageDisplay)}
        }
        Group {
          TableColumn("Target Profit", value: \LongCall.targetProfitDisplay) { Text($0.targetProfitDisplay) }
          TableColumn("Loss Limit %", value: \LongCall.lossLimitPercentageDisplay) { Text($0.lossLimitPercentageDisplay) }
        }
      }

This does not compile. Just added another Group. I get the dreaded "This compiler is unable to type-check this expression in a reasonable time":

Table(sortedTableData, selection: $selectedLongCallID, sortOrder: $sortOrder) {
        Group {
          TableColumn("Description", value: \LongCall.description) { Text($0.description) }.width(min: 200)
          TableColumn("Qty", value: \LongCall.quantity) { Text("\($0.quantity)") }.width(min: 40)
        }
        Group {
          TableColumn("Open Date", value: \LongCall.openDate) { Text($0.openDate.prettyDate()) }.width(min: 75)
          TableColumn("Days Held", value: \LongCall.daysHeld) { Text("\($0.daysHeld)") }
        }
        Group {
          TableColumn("Exp Date", value: \LongCall.expirationDate) { Text($0.expirationDate.prettyDate()) }.width(min: 75)
          TableColumn("Days til Exp", value: \LongCall.daysTilExpiration) { Text("\($0.daysTilExpiration)") }
        }
        Group {
          TableColumn("Debit Per Contract", value: \LongCall.openingDebitPerContract) { Text($0.openingDebitPerContract.formatToCurrency()) }
          TableColumn("Total Debit", value: \LongCall.totalDebit) { Text($0.totalDebit.formatToCurrency()) }
        }
        Group {
          TableColumn("Break Even Price", value: \LongCall.breakEvenPrice) { Text($0.breakEvenPrice.formatToCurrency()) }
          TableColumn("Target Profit %", value: \LongCall.targetProfitPercentageDisplay) { Text($0.targetProfitPercentageDisplay)}
        }
        Group {
          TableColumn("Target Profit", value: \LongCall.targetProfitDisplay) { Text($0.targetProfitDisplay) }
          TableColumn("Loss Limit %", value: \LongCall.lossLimitPercentageDisplay) { Text($0.lossLimitPercentageDisplay) }
        }
        Group {
           
        }
      }

The only reason I have two TableColumns per group is because that's the only way it would compile. If I add 3, it gives me the "reasonable time" error. I should be able to have up to 10 per Group. This is valid Swift code and since adopting SwiftuI, I spend more time reformatting code to get around this compiler error than anything else. What am I supposed to do here to have more than 10 TableColumns? What's the secret?

I have run into this issue many times, so I feel your pain! Unfortunately the SwiftUI Table is garbage and the best way to get a table in SwiftUI is to use a NSTableView. I have gone through months of trial and error trying to figure out how to get additional columns and some other features such as movable columns, but it is just a waste of time. I now have an NSTableView that I created using InterfaceBuilder with its view controller wrapped in a NSViewControllerRepresentable and a Coordinator class and it works perfect. I used a NSArrayController with Cocoa Bindings which allowed me to set the table up in Interface Builder with very little code. All you have to do is change your data model, Long Call, into "@objc member class Long Call: NSObject {}" instead of a structure. If you have never used Interface Builder before it may look daunting, but it really isn't. Especially for just a NSTableView, it will save you a lot of time and frustration. There are a few tutorials and gitHub projects that you can find with a google search, as well as some good examples on this forum. If you get stuck let me know and I can help you. I hope this helps!

I found this problem as well.

My solution is not very elegant, I'm afriad. I had to be very specific about the types. I moved the columns into their own @TableColumnBuilder with all the generics specified:

  @TableColumnBuilder<Weather.State.Row, Never>
  private var columns: TupleTableColumnContent<
    Weather.State.Row, Never, (
      TableColumn<Weather.State.Row, Never, Text, Text>,
      TableColumn<Weather.State.Row, Never, Text, Text>,
      TableColumn<Weather.State.Row, Never, Text, Text>,
      TableColumn<Weather.State.Row, Never, Text, Text>,
      TableColumn<Weather.State.Row, Never, Text, Text>,
      TableColumn<Weather.State.Row, Never, Text, Text>
    )
  > {
    TableColumn("Local Date/Time", value: \.dateTime)
    TableColumn("Temperature", value: \.temp)
    TableColumn("Apparent Temperature", value: \.apparentTemp)
    TableColumn("Dew Point", value: \.dewPoint)
    TableColumn("Humidity", value: \.humidity)
    TableColumn("Rain", value: \.rain)
  }

Though this is a lot of ugly specificity, it's the type inference that slowing Swift down here.

I was lucky because I don't need a sort comparator (hence the Never above) and all my labels and views are simply Texts.

There may be a way to clean this up further with buildPartialBlock

SwiftUI MacOS TableColumn compiler can't type-check expression in reasonable time.
 
 
Q