<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/FocusedValues",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI13FocusedValuesV"
  },
  "title" : "FocusedValues"
}
-->

# FocusedValues

A collection of state exported by the focused scene or view and its ancestors.

```
struct FocusedValues
```

## Creating Custom Focused Values

Use the `Entry` macro to create custom focused values by extending
`FocusedValues` with new properties:

```
extension FocusedValues {
    @Entry var focusedDocument: Binding<MyDocument>?
}
```

The `Entry` macro automatically generates the underlying key type and
provides the getter and setter for the focused value. Since the default
value for focused values is always `nil`, all focused values must be optional.

### Publishing Values in Your Views

Views publish focused values using the [`focusedValue(_:_:)`](/documentation/SwiftUI/View/focusedValue(_:_:)) modifier:

```
struct DocumentCellView: View {
    @Binding var document: MyDocument

    var body: some View {
        Text("Document Content")
            .focusedValue(\.focusedDocument, $document)
    }
}
```

For scene-wide values that should be available depending on the focused
scene, use [`focusedSceneValue(_:_:)`](/documentation/SwiftUI/View/focusedSceneValue(_:_:)):

```
struct DocumentViewer: View {
    @Binding var document: MyDocument

    var body: some View {
        Text("Document Content")
            .focusedSceneValue(\.focusedDocument, $document)
    }
}
```

### Accessing the current focused value

Use the [`FocusedValue`](/documentation/SwiftUI/FocusedValue) property wrapper in your [`App`](/documentation/SwiftUI/App) or [`View`](/documentation/SwiftUI/View) to
read the current value in the `body`. The [`FocusedBinding`](/documentation/SwiftUI/FocusedBinding) can be used as a
convenient way to access the `wrappedValue` if the value type of the focused
value is a `Binding`:

```
@main
struct DocumentApp: App {
    @FocusedBinding(\.focusedDocument) var currentDocument: MyDocument?

    var body: some Scene {
        DocumentGroup(newDocument: MyDocument()) { file in
            ContentView(document: file.$document)
                .focusedValue(\.focusedDocument, file.$document)
        }
        .commands {
            CommandGroup(after: .undoRedo) {
                Button("Increment") {
                    currentDocument?.value += 1
                }.disabled(currentDocument == nil)
            }
        }
    }
}
```

## Topics

### Getting the value for a key

[`subscript(_:)`](/documentation/SwiftUI/FocusedValues/subscript(_:))

Reads and writes values associated with a given focused value key.

## Relationships

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

---

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)