---
title: "State(wrappedValue:)"
framework: swiftui
role: symbol
role_heading: Macro
path: "swiftui/state(wrappedvalue:)"
---

# State(wrappedValue:)

Creates a property with a wrapped value that can read and write a value managed by SwiftUI.

## Declaration

```swift
@attached(accessor, names: named(init), named(get), named(set)) @attached(peer, names: prefixed(`_`), prefixed(__), prefixed(`$`)) macro State<Value>(wrappedValue: Value)
```

## Overview

Overview important: When you build with Xcode 26 or earlier, the system uses the State property wrapper instead. Use state as the single source of truth for a given value type that you store in a view hierarchy. Create a state value in an App, Scene, or View by applying the @State attribute to a property declaration with an initial value. Declare state as private to prevent setting it in an initializer, which can conflict with the storage management that SwiftUI provides: struct PlayButton: View {     @State private var isPlaying: Bool = false // Create the state.

var body: some View {         Button(isPlaying ? "Pause" : "Play") { // Read the state.             isPlaying.toggle() // Write the state.         }     } } For more information on sharing state properties with subviews, and storing Observable objects in state, see State().

## See Also

### Creating and sharing view state

- [Managing user interface state](swiftui/managing-user-interface-state.md)
- [State()](swiftui/state().md)
- [State(initialValue:)](swiftui/state(initialvalue:).md)
- [State](swiftui/state.md)
- [Bindable](swiftui/bindable.md)
- [Binding](swiftui/binding.md)
