<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/AttributedTextSelection/Attributes/subscript(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI23AttributedTextSelectionV10AttributesVyQrqd__mc10Foundation0C9StringKeyRd__s8Sendable5ValueRpd__luip::OverloadGroup"
  },
  "title" : "subscript(_:)"
}
-->

# subscript(_:)

Returns a sequence which iterates of the values of a single
attribute.

```
subscript<K>(type: K.Type) -> some Sequence<Optional<K.Value>> where K : AttributedStringKey, K.Value : Sendable { get }
```

## Overview

In the case of a range selection, the returned sequence is based
on the runs of the specified attribute, not the runs over all
attributes.

```
selection.attributes(in: text)[MyAttribute.self].contains(myValue)
```

---

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)