๐Ÿ”ธstate value

โ•ฑ๐Ÿšง under construction

SwiftUI โŸฉ view โŸฉ state โŸฉ value

The state of a view, use @State to declare and initialize a state value of a view. Also called a state property.

struct ContentView: View {

    // โญ๏ธ declare & initialize a state value
    @State var isOn = true
    
    // UI
    var body: some View { ... }
    
}
  • SwiftUI updates your views' appearances automatically whenever your app's state changes.

  • One common way to change view states is through user interaction, such as when a person taps a Button.

Last updated