<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/LayoutSubview/subscript(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI13LayoutSubviewVy5ValueQzxmcAA0cE3KeyRzluip"
  },
  "title" : "subscript(_:)"
}
-->

# subscript(_:)

Gets the value for the subview that’s associated with the specified key.

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

## Overview

If you define a custom layout value using [`LayoutValueKey`](/documentation/SwiftUI/LayoutValueKey),
you can read the key’s associated value for a given subview in
a layout container by indexing the container’s subviews with
the key type. For example, if you define a `Flexibility` key
type, you can put the associated values of all the layout’s
subviews into an array:

```
let flexibilities = subviews.map { subview in
    subview[Flexibility.self]
}
```

For more information about creating a custom layout, see [`Layout`](/documentation/SwiftUI/Layout).

---

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)