Swift UI How can I get the click of a button to change the wording of Label

Using SwiftUI how can I get the click of a "Button" to change the wording of a "Label" and/or "Text" Field?

I have tried:-

let myLabel = Label  {
        Text("Text to be Changed"
         .foregrorundStyle ......
   } icon: {
        ......
   }
....
.....
Button("Change Label Wording"){
   myLabel.stringValue = "Changed text"
}

This gives me two problems (at least):

  1. I cannot get the label to display
  2. The myLabel.stringValue = "Changed text gives me the error:
  • Type '()' cannot conform to 'View'
  • Value of type 'Label<some View, some View>' has no member 'stringValue'

What have I done wrong?

my label should be a state var. And you cannot change with string value, but just reassign a new label:

struct ContentView: View {
    
    @State private var myLabel = Label("Text to be Changed", systemImage: "circle")
    
    var body: some View {
        Spacer()
        Button("Change Label Wording"){
            myLabel = Label("Changed text", systemImage: "star")
        }
        Spacer()
        myLabel
        Spacer()
    }
}

You could also do it differently.

Create a state variable

@State private var newLabel = false

Toggle in button action:

Button("Change Label Wording"){
   newLabel.toggle()
}

Here is a small code snippet to show:

struct ContentView: View {
    
    @State private var newLabel = false

    var body: some View {
        Spacer()
        Button("Change Label Wording"){
            newLabel.toggle()
//            myLabel.stringValue = "Changed text"
        }
        Spacer()
        Text(newLabel ? "Changed text" : "Text to be Changed")
        // Or this form
        Spacer()
        if newLabel {
            Text("Changed text (2)")
        } else {
            Text("Text to be Changed (2)")
        }
        Spacer()
    }
}
Swift UI How can I get the click of a button to change the wording of Label
 
 
Q