Failed to produce diagnostic for expression; please file a bug report

Someone know how to fix that?

Code Block import SwiftUI
import UIKit
struct ContentView: View {
   
  var Count = Int(0)
   
   
   
  var body: some View { error: "Failed to produce diagnostic
for expression; please file a bug report"
    VStack {
      Image("IMG")
        .padding(.trailing, 353.844)
        .scaleEffect(0.3)
        .fixedSize()
      Spacer()
      Text("Count:" + String(Count))
        .font(.largeTitle)
        .animation(.easeIn(duration: 0.5))
       
      Spacer()
       
      Button(Text(Count), action: {
        Count += 1
      })
    }
  }
}
struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
    ContentView()
  }
}
 


Someone know how to fix that?

Please try this:
Code Block
struct ContentView: View {
@State var count: Int = 0
var body: some View { //error: "Failed to produce diagnostic for expression; please file a bug report"->gone, see `<-`
VStack {
Image("IMG")
.padding(.trailing, 353.844)
.scaleEffect(0.3)
.fixedSize()
Spacer()
Text("Count:\(count)")
.font(.largeTitle)
.animation(.easeIn(duration: 0.5))
Spacer()
Button("\(count)", action: { //<-
count += 1
})
}
}
}


Button does not have an initializer taking Text and action closure in this order. And Text does not have an initializer taking Int.
The current Swift compiler is too weak to diagnose type-related errors inside ViewBuilder, you should better send a feedback as suggested.


Some other things:
  • In Swift, only type names should use Capital case identifiers. Property names should start with lowercase letter.

  • Use @State, if you want to modify the value in some action closure.

  • You should better use String Interpolation literals more, especially in SwiftUI.

Your confusion comes probably from that Text is not a conversion to String, it is a View.

If you just write (with Count better with lowercase):
Code Block
      Button(String(count), action: {

You'll get what you expect.
Failed to produce diagnostic for expression; please file a bug report
 
 
Q