0

The following code does work for me...

VStack {
    ForEach(0..<self.rows, id: \.self) { row in
        HStack {
            ForEach(0..<self.columns, id: \.self) { column in

                //let data = self.item(row: row, column: column)

                Group {
                    if self.item(row: row, column: column) != nil {

                        self.content(self.item(row: row, column: column)!).frame(width: geometry.size.width/CGFloat(self.columns))

                    } else {
                        Spacer()
                    }
                }
            }
        }
    }
}

However, when I uncomment data variable and replaced item() calls with data usage, and even add return Group { } it stops working and cannot infer return type?

davidev
  • 7,694
  • 5
  • 21
  • 56
Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143
  • 4
    You cannot declare variables inside the function builders, compare https://stackoverflow.com/q/56616368/1187415 for a similar issue. – Martin R Nov 27 '19 at 09:59

1 Answers1

0

in Xcode 12 beta simply add type to param.

My sample code: (I prefer to divide SwiftUi stuff.. too messy otherwise..) See near color

struct Issue: Identifiable{
        var id  = UUID()
        var name = ""
        var fakeMsg = ""
        var operatorInCharge = ""
        var solved = false
    }
    
    

struct CurrentIssuesView: View {
    
    let roomIssues = [
        Issue(name: "ROOM 1", fakeMsg: "2020-09-05 proiettore", operatorInCharge: "m.a", solved: true),
        Issue(name: "ROOM 1", fakeMsg: "2020-09-04 wifi", operatorInCharge: "a.b"),
        Issue(name: "ROOM 2", fakeMsg: "2020-09-04 Audio", operatorInCharge: "m.c", solved: true),
        Issue(name: "ROOM 3", fakeMsg: "2020-09-04 KBD", operatorInCharge: "m.d")
    ]
    
    
    var body: some View {
        
        let vs = VStack{
            
            Text("Current ISSUES")
            
            List(roomIssues) { (issue: Issue) in
                
                let color = issue.solved ? Color.green : Color.red
                HStack{
                    Text(issue.name).font(.system(size: 20)).foregroundColor(color)
                    Text(issue.fakeMsg)
                }
            }
        }
        return vs
    }
}

I got:

enter image description here

ingconti
  • 10,876
  • 3
  • 61
  • 48