<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/State(initialValue:)",
  "metadataVersion" : "0.1.0",
  "role" : "Macro",
  "symbol" : {
    "kind" : "Macro",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI5State12initialValueyx_tclufm"
  },
  "title" : "State(initialValue:)"
}
-->

# State(initialValue:)

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

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

## Overview> Important: When you build with Xcode 26 or earlier, the system uses the ``doc://com.apple.SwiftUI/documentation/SwiftUI/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`](/documentation/SwiftUI/App), [`Scene`](/documentation/SwiftUI/Scene),
or [`View`](/documentation/SwiftUI/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:

```swift
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 <doc://com.apple.documentation/documentation/Observation/Observable> objects in state, see [`State()`](/documentation/SwiftUI/State()).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)