What does "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions" mean?

Here is my code:

Please show the full code, as text, not a partial screenshot.

May be you have too many views (more than 11) in the top level VStack. But we would need to see the full code to check.

I've got 22,000 lines of SwiftUI in my app (Dvn8). I've seen this lots of times.

Most commonly, it's that your view is composed of more than 10 views, and if you'll either Group { } some of the components together, or break them out into separate functions using @ViewBuilder or AnyView, the compiler will suddenly be able to grok how to compile it all. This is something I never saw in UIKit, but it crops up a lot in SwiftUI.

Note, too, that it's not arbitrary. Once you've refactored into something the compiler can handle, it won't complain about it again.

I've also seen this crop up when I was lazy and allowed for auto type coercion - like, for example, if I've defined a var x = 0.0 but then later on attempt to access x as a CGFloat and then still later on as a Double. The compiler seems to dislike lazy coercions, so I've made a point of always being explicit in my declarations - that has seemed to minimize how often this error shows up.

Finally, if I just can't seem to find the culprit, I will go ahead and break the view into function calls that return @ViewBuilder sub-views. Almost always, this results in cleaner to read code for me, and easier to compile code for Xcode. And then I hit myself on the forehead, do my best Homer Simpson "Doh!" impersonation, and I increment iGottaRememberToDoThisMoreOften by 1.

In general, I would LOVE it if Xcode were more explicit in its errors - I've spent hours trying to track down some rather vague (although friendly!) error messages.

What does "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions" mean?
 
 
Q