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

İ am getting "Failed to produce a diagnostic for expression; please file a bug report" error.

import SwiftUI



struct ContentView: View {

    let lifeformanalyzer = Lifeformanalyzer()

    @State var text = ""

    @State var title = "Merhaba insan!"

    

    var body: some View {   ————> error is here

        VStack {

            Image(systemName: "face.smiling.fill")

                .imageScale(.large)

                .foregroundColor(.accentColor)

                .padding(.top, 50)

            Text(title)

                .font(.largeTitle)

            

            Spacer()

            

            TextField("Birşey yazın", text: $text)

                .multilineTextAlignment(.center)

                .frame(width: 300)

            

            Spacer()

            

            Button("Gönder") {

                submit()

            }

            

            Spacer()

            

        }

            

            

        .padding()

        .frame(maxWidth: .infinity, maxHeight: .infinity)

        .background(Color(red: 0.024, green: 0.392, blue: 0.549))

        .ignoresSafeArea()

            

    func submit() {

        

            }

    var title = "Merhaba \(lifeformanalyzer.processLifeform(text: text))!"

        

        

    }





    

    

    

    


}

The other swift file Lifeformanalyzer:

class Lifeformanalyzer {


    

    func processLifeform(text: String) -> String{

        

        text.lowercased().contains("vak")

        ? "ördek" : "insan"

    }

}

bracket before text parameter value var title = "Merhaba \(lifeformanalyzer.processLifeform(text: [text))!"

var title = "Merhaba (lifeformanalyzer.processLifeform(text: text))!"

or

var title = "Merhaba (lifeformanalyzer.processLifeform(text: $text))!"

There are several errors:

  • you redeclare var title, which is already declared as state var. Why ?
  • you declare func submit inside the View. take it out
  • text parameter is wrong ([text) instead of text
  • if you want to change the title value, you can do it in a func. In submit (if that's when you want to change)

This compiles

struct ContentView: View {

    let lifeformanalyzer = Lifeformanalyzer()
    @State var text = ""
    @State var title = "Merhaba insan!"

    func submit() {
        title = "Merhaba \(lifeformanalyzer.processLifeform(text: text))!"
     }

    var body: some View {

        VStack {

            Image(systemName: "face.smiling.fill")
                .imageScale(.large)
                .foregroundColor(.accentColor)
                .padding(.top, 50)

            Text(title)
                .font(.largeTitle)

            Spacer()

            TextField("Birşey yazın", text: $text)
                .multilineTextAlignment(.center)
                .frame(width: 300)

            Spacer()

            Button("Gönder") {
                submit()
            }

            Spacer()

        }
        .padding()
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .background(Color(red: 0.024, green: 0.392, blue: 0.549))
        .ignoresSafeArea()


//    var title = "Merhaba \(lifeformanalyzer.processLifeform(text: [text))!"

    }

}

class Lifeformanalyzer {

    func processLifeform(text: String) -> String{

        text.lowercased().contains("vak") ? "ördek" : "insan"

    }

}

Note: when you paste code, try to avoid so many blank lines. Use Paste and Match Style and use code formatter tool.

"Failed to produce a diagnostic for expression; please file a bug report" error.
 
 
Q