英文:
Sections in a SwiftUI MacOS Table will not build
问题
在这段代码中,编译器建议你将表达式分解为明确的子表达式以便更好地进行类型检查。你可以尝试将 theTable
这个视图的构建过程拆分为多个步骤,以减轻编译器的负担。
var theTable: some View {
ForEach(groupedFlights.keys.sorted()){ key in
Text("DaySequenceNumber: \(key)")
Table(groupedFlights[key]){
TableColumn("FLIGHTNO", value: \.flightNo)
TableColumn("DATE", value: \.date)
TableColumn("FROM", value: \.from)
TableColumn("TO", value: \.to)
TableColumn("ACREG", value: \.acReg)
TableColumn("STD", value: \.std)
TableColumn("STA", value: \.sta)
}
}
}
通过将 theTable
拆分为多个子表达式,你可以更好地帮助编译器理解代码的结构,从而提高类型检查的效率。
英文:
I am trying to create a Table in SwiftUI for MacOS with sections in the table. The compiler wants me to break it up into sub-expressions, but I dont understand how to do this.
This is the error:
> The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
It happens on the ForEach here:
var theTable: some View {
ForEach(groupedFlights.keys.sorted()){ key in
Text("DaySequenceNumber: \(key)")
Table(groupedFlights[key]){
TableColumn("FLIGHTNO", value: \.flightNo)
TableColumn("DATE", value: \.date)
TableColumn("FROM", value: \.from)
TableColumn("TO", value: \.to)
TableColumn("ACREG", value: \.acReg)
TableColumn("STD", value: \.std)
TableColumn("STA", value: \.sta)
}
}
}
private var groupedFlights: [Int: [Flight]] {
Dictionary(grouping: showingFlights, by: \.daySequenceNo)
}
The Flight class:
import Foundation
import RealmSwift
class Flight: Object, ObjectKeyIdentifiable{
@Persisted(primaryKey: true) var id:ObjectId
@Persisted var flightNo:String
@Persisted var date:String
@Persisted var from:String
@Persisted var to:String
@Persisted var acReg:String
@Persisted var std:String
@Persisted var sta:String
@Persisted var daySequenceNo:Int
@Persisted var crewList:CrewList?
var idString:String{
id.description
}
}
How can i break down theTable?
答案1
得分: 0
我在另一个帖子中找到了解决方案:
所以我在这一行中添加了 as Flight:
Table(groupedFlights[key]! as [Flight]){
英文:
I found the solution in another thread:
macOS SwiftUI Table with more than 10 columns?
So I added as Flight to this line:
Table(groupedFlights[key]! as [Flight]){
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论