<!--
{
  "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" : "Foundation",
  "identifier" : "/documentation/Foundation/DiscontiguousAttributedSubstring/subscript(_:)-1bcls",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation32DiscontiguousAttributedSubstringVy5ValueQzSgxmcAA0C9StringKeyRzs8SendableAERQluip"
  },
  "title" : "subscript(_:)"
}
-->

# subscript(_:)

Returns an attribute value that corresponds to an attributed string key.

```
subscript<K>(_: K.Type) -> K.Value? where K : AttributedStringKey, K.Value : Sendable { get set }
```

## Overview

This subscript returns `nil` unless the specified attribute exists, and is present and identical for the entire discontiguous attributed substring. To find portions of an attributed string with consistent attributes, use the `runs` property.
Getting or setting stringwide attributes with this subscript has `O(n)` behavior in the worst case, where n is the number of runs.

---

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)