In a Document app for MacOS using latests non-beta tools.
This works:
Table(transactions) {
TableColumn("Payee") { transaction in
Text("\(transaction.payee ?? "no payee")")
}
}
But this column version does not:
Table(transactions) {TableColunn("Payee", value: \.payee)
The error is about the .payee keyPath "Key path value type 'String?' cannot be converted to contextual type 'String'"
payee is an optional property of the @Model class TheTransaction. The class has an init and also code to make it codeable (for JSON import).
If the model is in a standard struct there is no problem and both work, although the former is not not sortable.
The goal is to list all the transactions in a Table, sortable by any column. Straighforward when not using SwiftData.
Anyone have an example of presenting SwiftData in a Table and eligible for sorting?