<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/ContainerValues/subscript(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI15ContainerValuesVy5ValueQzxmcAA0cE3KeyRzluip"
  },
  "title" : "subscript(_:)"
}
-->

# subscript(_:)

Accesses the particular container value associated with a custom key.

```
subscript<Key>(key: Key.Type) -> Key.Value where Key : ContainerValueKey { get set }
```

## Overview

Create a custom container value by declaring a new property
in an extension to the container values structure and applying
the [`Entry()`](/documentation/SwiftUI/Entry()) macro to the variable declaration:

```
extension ContainerValues {
    @Entry var myCustomValue: String = "Default value"
}
```

You use custom container values the same way you use system-provided
values, setting a value with the [`containerValue(_:_:)`](/documentation/SwiftUI/View/containerValue(_:_:)) view
modifier, and reading values from a [`Subview`](/documentation/SwiftUI/Subview) provided by the
`subviews` modifier. You can also provide a dedicated view modifier as a
convenience for setting the value:

```
extension View {
    func myCustomValue(_ myCustomValue: String) -> some View {
        containerValue(\.myCustomValue, myCustomValue)
    }
}
```

---

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)