Xcode 12 Can't figure out the type???

Once again, the most frustrating and weird error message: "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions"

Code Block
struct TimePosition: View {
var scale: Double
var body: some View {
GeometryReader { geometry in
VStack {
ForEach(0..<Int(geometry.size.height)/Int(1/self.scale), id:\.self) { y in
Text(String(Double(y)/4.0)).position(x: geometry.size.width/2, y: CGFloat(y)).font(.system(size: 8.0)).foregroundColor(.gray)
}
}
}
}
}


So, how exactly does one break this up?

Replies

Really odd behavior.

Seems Text prefers String interpolation rather than String.init:
Code Block
struct TimePosition: View {
    var scale: Double
    var body: some View {
        GeometryReader { geometry in
            VStack {
                ForEach(0..<Int(geometry.size.height)/Int(1/self.scale), id:\.self) { y in
                    Text("\(Double(y)/4.0)")
                        .position(x: geometry.size.width/2, y: CGFloat(y)).font(.system(size: 8.0))
                        .foregroundColor(.gray)
                }
            }
        }
    }
}


But I do not understand why type-checking an expression like Text(String(Double(y)/4.0)).position(x: geometry.size.width/2, y: CGFloat(y)).font(.system(size: 8.0)).foregroundColor(.gray) takes unreasonable time.
Awesome, works for me. Reads slightly cleaner, too. But yeah, can't think why they are are different. I'd love to know... I think I'll ask on the Swift forums.

In any case, thanks!
Hi, could you file a bug report at https://feedbackassistant.apple.com with your test case to make sure we don't lose track of this?
Filed: FB7802730