---
title: "subscript(dynamicMember:)"
framework: foundation
role: symbol
role_heading: Instance Subscript
path: "foundation/attributedstring/subscript(dynamicmember:)-34zdf"
---

# subscript(dynamicMember:)

Returns an attribute value that a key path indicates.

## Declaration

```swift
@preconcurrency subscript<K>(dynamicMember keyPath: KeyPath<AttributeDynamicLookup, K>) -> K.Value? where K : AttributedStringKey, K.Value : Sendable { get set }
```

## Discussion

Discussion This subscript returns nil unless the specified attribute exists, and is present and identical for the entire attributed string or substring. To find portions of the 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.

## See Also

### Accessing Whole-String Attributes

- [AttributeDynamicLookup](foundation/attributedynamiclookup.md)
- [subscript(dynamicMember:)](foundation/attributedstring/subscript(dynamicmember:)-9modq.md)
- [ScopedAttributeContainer](foundation/scopedattributecontainer.md)
