【发布时间】:2022-12-31 01:45:26
【问题描述】:
我正在尝试在其标题的某个部分中显示行数,如下所示为 COUNTHERE。我遇到的问题是我不能在 if 语句中放入任何不是视图的代码,所以我无法计算任何东西。想法?
struct Day1View: View {
var displayEmployees: [Employee]
var body: some View {
List {
Section(header: Text("Early (\(COUNTHERE)")) {
ForEach(displayEmployees) { employee in
if employee.shift == .early {
switch employee.post {
case .kitchen : Text(employee.name).foregroundColor(.blue)
case .floor : Text(employee.name).foregroundColor(.yellow)
case .upstairs : Text(employee.name).foregroundColor(.red)
case .greeting : Text(employee.name).foregroundColor(.green)
default : Text(employee.name).foregroundColor(.gray)
}
}
}
}
}
【问题讨论】: