<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/AttributeContainer/subscript(dynamicMember:)-3jcvx",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation18AttributeContainerV13dynamicMemberAA06ScopedbC0VyxGs7KeyPathCyAA0B6ScopesOxmG_tcAA0B5ScopeRzluip"
  },
  "title" : "subscript(dynamicMember:)"
}
-->

# subscript(dynamicMember:)

Returns the attribute container that corresponds to a specified key path.

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

## Discussion

Use this subscript when you need to work with an explicit attribute scope. For example, the SwiftUI [`foregroundColor`](/documentation/Foundation/AttributeScopes/SwiftUIAttributes/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 `myAttributeContainer.uiKit.foregroundColor` to disambiguate and explicitly use the UIKit attribute.

---

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)