Compiler Error with SwiftUI Project on iOS 13 on Xcode 12

I'm getting an error when trying to compile my project using xcode 12.

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

The compiler hints that the error is at the last modifier .offset() in this snippet:

Code Block swift
func circle(geometry: GeometryProxy, index: Int) -> some View {
    return Circle()
      .fill(Color.mediumGray)
      .frame(width: geometry.size.width / 5, height: geometry.size.height / 5)
      .scaleEffect(!self.isAnimating ? 1 - CGFloat(index) / 4 : 0.1 + CGFloat(index) / 5)
      .offset(y: geometry.size.width / 10 - geometry.size.height / 2)
  }

Answered by Developer Tools Engineer in 615471022
This seems to be a bug in the compiler where it takes too long to produce the correct diagnostic. It isn't necessarily related to the .offset modifier - this is just the line where the expression ends.

It looks like the real issue is that Color doesn't have a member called mediumGray. When I comment out the last 2 modifiers, that is the error message I get. The following code does compile in an iOS project in Xcode 12 using Color.gray instead of Color.mediumGray:

Code Block
struct ContentView: View {
    var isAnimating: Bool
    func circle(geometry: GeometryProxy, index: Int) -> some View {
        return Circle()
          .fill(Color.gray)
          .frame(width: geometry.size.width / 5, height: geometry.size.height / 5)
          .scaleEffect(!self.isAnimating ? 1 - CGFloat(index) / 4 : 0.1 + CGFloat(index) / 5)
          .offset(y: geometry.size.width / 10 - geometry.size.height / 2)
      }
var body: some View {
...
}
}


Could you please file a bug using Feedback Assistant and attach your Xcode project? Thank you!
Have you tried breaking up the expression as suggested?
Code Block
    func circle(geometry: GeometryProxy, index: Int) -> some View {
        let frameWidth = geometry.size.width / 5
        let frameHeight = geometry.size.height / 5
        let scale = !self.isAnimating ? 1 - CGFloat(index) / 4 : 0.1 + CGFloat(index) / 5
        let offsetY = geometry.size.width / 10 - geometry.size.height / 2
        return Circle()
            .fill(Color.mediumGray)
            .frame(width: frameWidth, height: frameHeight)
            .scaleEffect(scale)
            .offset(y: offsetY)
    }


Accepted Answer
This seems to be a bug in the compiler where it takes too long to produce the correct diagnostic. It isn't necessarily related to the .offset modifier - this is just the line where the expression ends.

It looks like the real issue is that Color doesn't have a member called mediumGray. When I comment out the last 2 modifiers, that is the error message I get. The following code does compile in an iOS project in Xcode 12 using Color.gray instead of Color.mediumGray:

Code Block
struct ContentView: View {
    var isAnimating: Bool
    func circle(geometry: GeometryProxy, index: Int) -> some View {
        return Circle()
          .fill(Color.gray)
          .frame(width: geometry.size.width / 5, height: geometry.size.height / 5)
          .scaleEffect(!self.isAnimating ? 1 - CGFloat(index) / 4 : 0.1 + CGFloat(index) / 5)
          .offset(y: geometry.size.width / 10 - geometry.size.height / 2)
      }
var body: some View {
...
}
}


Could you please file a bug using Feedback Assistant and attach your Xcode project? Thank you!
Hi! Thanks for your reply!
Indeed the issue was because Color.mediumGray. Thank you!
I have the same issue, no color is being used. Its my body argument with some if then else statements. Worked fin on previous versions of Xcode.

The problem is in this string:

!self.isAnimating ? 1 - CGFloat(index) / 4 : 0.1 + CGFloat(index) / 5

If you change it to:

!self.isAnimating ? CGFloat(1.0) - CGFloat(index) / 4 : CGFloat(0.1) + CGFloat(index) / 5    

this bug will disappear. Compiler of XCode 13 can't resolve a type for some reason.

Compiler Error with SwiftUI Project on iOS 13 on Xcode 12
 
 
Q