Declaring @State Properties
Add @State to hold mutable view-local data.
Meet the @State Wrapper
You declare mutable view-local data by marking a property with @State. This property wrapper tells SwiftUI to store and watch the value for you. 🏷️
@State private var count = 0Always Give It a Default
A @State property needs an initial value right where you declare it. SwiftUI uses it to create the storage the first time the view appears.
@State private var isOn = falseAll lessons in this course
- Why Views Need State
- Declaring @State Properties
- Building a Tap Counter
- Toggling Visibility with State