Here's how to make the example you proposed:
Code Block swift| import SwiftUI |
|
| struct ContentView: View { |
| @State var buttonText = "" |
|
| var body: some View { |
| VStack { |
| TextField("Text Here", text: $buttonText) |
| .padding() |
| .textFieldStyle(RoundedBorderTextFieldStyle()) |
| |
| Button(self.buttonText) { |
| /* code to be executed when button is pressed */ |
| } |
| } |
| } |
| } |
I suggest that you read about the @State property wrapper and how SwiftUI Views work in general.
In short, SwiftUI is a state-driven UI framework, meaning that every variable which is somehow displayed on screen that you change at some point in time will immediate refresh the view with the new data. It makes updating things and listening to changes an absolute breeze.
I hope I helped!