<!--
{
  "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(in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI23AttributedTextSelectionV10attributes2inAC10AttributesVy_10Foundation0C6StringVGAJ_tF"
  },
  "title" : "attributes(in:)"
}
-->

# attributes(in:)

Obtain a lazy sequence of all attribute values the selection has in a
given text.

```
func attributes(in text: AttributedString) -> AttributedTextSelection.Attributes<AttributedString>
```

## Discussion

The attribute values of a selection are the attribute values of each run
that is fully or partially selected, or the typing attributes in the
case the selection is an insertion point.

By default, the sequence contains the attribute container for every
run or the typing attributes. Use the [`AttributedTextSelection.Attributes`](/documentation/SwiftUI/AttributedTextSelection/Attributes)’ subscript to
obtain only the values for a single attribute:

```
selection.attributes(in: text)[\.foregroundColor].contains(.red)
```

---

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)