Responding to a button tap
In this section, we will begin making a view responsive by examining the simplest case; that is, building a view that needs to respond to a simple user event, a button tap, and changing the view appearance in response.
Let’s start by trying to write the first thing that would intuitively come to mind; let’s change a variable’s value and have the view respond to that value change, as shown in the following code example:
import SwiftUI struct MyViewStruct: View { var name = "Mary" var body: some View { VStack(spacing: 20) { Text("Variables in structs are immutable") .fontWeight(.heavy) ...