<!--
{
  "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/AttributeScope",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation14AttributeScopeP"
  },
  "title" : "AttributeScope"
}
-->

# AttributeScope

A type that organizes attributes into a grouping, and supports dynamic member lookup and serialization of attribute keys.

```
protocol AttributeScope : DecodingConfigurationProviding, EncodingConfigurationProviding, SendableMetatype
```

## Overview

Attribute owners — typically frameworks — define attributes with [`AttributedStringKey`](/documentation/Foundation/AttributedStringKey) types. To allow access to attributes with dynamic member lookup, owners create one or more structures that conform to [`AttributeScope`](/documentation/Foundation/AttributeScope). The scopes provide short names for their attributes that map to the [`AttributedStringKey`](/documentation/Foundation/AttributedStringKey) type. The following example shows how to do this:

```swift
struct TextStyleAttributes : AttributeScope {
    let foregroundColor : ForegroundColorAttribute // ForegroundColorAttribute.Value == Color
    let backgroundColor : BackgroundColorAttribute // BackgroundColorAttribute.Value == Color
    let underlineStyle : UnderlineStyleAttribute // UnderlineStyleAttribute.Value == UnderlineStyle
    // etc.
}
```

This allows callers to use a syntax like `myAttributedString.foregroundColor = .red`.

## Topics

### Supporting Coding Configurations

[`encodingConfiguration`](/documentation/Foundation/AttributeScope/encodingConfiguration)

The configuration for encoding the attribute scope.

[`decodingConfiguration`](/documentation/Foundation/AttributeScope/decodingConfiguration)

The configuration for decoding the attribute scope.



---

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)