DEV Community

Saurabh Chavan
Saurabh Chavan

Posted on

What is @State in SwiftUI

SwiftUI uses the @State property wrapper to allow us to modify values inside a struct, which would normally not be allowed because structs are value types.

struct PlayButton: View {
    @State private var isPlaying: Bool = false

    var body: some View {
        Button(isPlaying ? "Pause" : "Play") {
            isPlaying.toggle()
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)