๐Ÿ”ฐview state

SwiftUI โŸฉ view โŸฉ state

The state of a view, add @State before a property of a view to tell SwiftUI to manage the storage for a value.

struct ContentView: View {

    // โญ๏ธ view state (data)
    @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.

  • state๏ผšcurrent value of a variable

Last updated