SwiftUI Reference

SwiftUi @State

 State is almost entirely managed by SwiftUI. A State property is only meant to be accessed from inside the views body or from a function, so  it is best practice to always declare state properties as private. A State value is always an instance. The view is automatically update when there is a value change.

State Toggle Example

struct ContentView : View {
    @State private var name = true

    var body: some View {
        VStack {
            if name {
                Text(“Swiftly Dierkes”)

    Toggle(isOn: $name) {
        Text(“Display Name”)
     } .padding()



Swift UI Binding

You can get a binding from a state with the binding property, or by using the $ prefix operator.


Made with ❤ By Mason Dierkes

Close Menu