I'm trying to figure out how to change the text of a string when a button is pressed in SwiftUI.
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
let title = Text("Button Not Clicked")
.font(.title)
.fontWeight(.heavy)
.foregroundColor(.red)
.padding()
.frame(height: 0.0)
}
Button(action: {
title.text = "Button Clicked!"
}) {
Text("Click Here")
}
}
}
So far, I've tried to change the string using 'title.text = (string)' but that doesn't work. Any ideas?