The compiler is unable to time-check

Hi, I'm relatively new to Xcode and I've just received an error while working on my fitness dare app that I'm not sure how to interpret.

It says

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

But as you see in the following my code shouldn't actually be too complex I think.

Thanks a lot for any help.

This is the code that prompts the error:

Code Block
struct PlayScreen: View {
   
    @Binding var name: [String]
    @State var qCount = 0
    let qCountMax = 1
    @Binding var pCount: Int
    @State var p1 = 0
    @State var p2 = 1
   
  var body: some View {
     
    let q1 = ["Whoever can do more situps out of " + name[p1] + " & " + name[p2] " gets two points.",
      name[p1] + " & " + name [p2] +" who is quicker to touch the ceiling? Winner gets a point.",
      ]
        
    VStack(alignment: .center) {
      
       
    Spacer ()
     
     
      Text(q1[qCount])
        .multilineTextAlignment(.center)
        .padding(.bottom, 10.0)
    Spacer()
         
        
      Button(action: {
         
        if qCount < qCountMax {
          qCount += 1
        }
         
        else if qCount == qCountMax {
          qCount = 0
        }
         
        p1 = Int.random(in: 1 ... pCount)
        p2 = Int.random(in: 0 ... pCount)
         
        if p2==p1 {p2 = 0}
         
      }, label: {
        Text("next")
      }).frame(width: 200.0, height: 100.0)
      .foregroundColor(.secondary)
         
    }
   
  }
}




Accepted Answer

But as you see in the following my code shouldn't actually be too complex I think.

The compiler would not think as you think.

Try this:
Code Block
let q1: [String] = ["Whoever can do more situps out of " + name[p1] + " & " + name[p2] + " gets two points.",
name[p1] + " & " + name[p2] + " who is quicker to touch the ceiling? Winner gets a point.",
]

Or this:
Code Block
let q1 = ["Whoever can do more situps out of \(name[p1]) & \(name[p2]) gets two points.",
"\(name[p1]) & \(name[p2]) who is quicker to touch the ceiling? Winner gets a point.",
]


Swift compiler is not good at parsing binary operations especially when they include literals.
Adding type annotations would help in some simple cases, or not using binary operator would work.

The first option worked brilliantly thank's a lot!
The compiler is unable to time-check
 
 
Q