<!--
{
  "availability" : [
    "iOS: 14.0.0 - 27.0.0",
    "iPadOS: 14.0.0 - 27.0.0",
    "macCatalyst: 14.0.0 - 27.0.0",
    "macOS: 11.0.0 - 27.0.0",
    "tvOS: 14.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0",
    "watchOS: 7.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/PreviewContext/subscript(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI14PreviewContextPy5ValueQyd__qd__mcAA0cD3KeyRd__luip"
  },
  "title" : "subscript(_:)"
}
-->

# subscript(_:)

Returns the context’s value for a key, or a the key’s default value
if the context doesn’t define a value for the key.

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

---

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)