---
title: "subscript(dynamicMember:)"
framework: foundation
role: symbol
role_heading: Instance Subscript
path: "foundation/attributedstringprotocol/subscript(dynamicmember:)-55pcu"
---

# subscript(dynamicMember:)

Returns a scoped attribute container that a key path indicates.

## Declaration

```swift
subscript<S>(dynamicMember keyPath: KeyPath<AttributeScopes, S.Type>) -> ScopedAttributeContainer<S> where S : AttributeScope { get set }
```

## Discussion

Discussion Use this subscript when you need to work with an explicit attribute scope. For example, the SwiftUI foregroundColor attribute overrides the attribute in the AppKit and UIKit scopes with the same name. If you work with both the SwiftUI and UIKit scopes, you can use the syntax myAttributedString.uiKit.foregroundColor to disambiguate and explicitly use the UIKit attribute. The attribute container that this method returns contains only attributes that exist, and are present and identical for the entire attributed string. 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

- [subscript(_:)](foundation/attributedstringprotocol/subscript(_:)-4thnp.md)
- [subscript(dynamicMember:)](foundation/attributedstringprotocol/subscript(dynamicmember:)-2wake.md)
- [AttributeDynamicLookup](foundation/attributedynamiclookup.md)
- [ScopedAttributeContainer](foundation/scopedattributecontainer.md)
