<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation18AttributeContainerV"
  },
  "title" : "AttributeContainer"
}
-->

# AttributeContainer

A container for attribute keys and values.

```
@dynamicMemberLookup struct AttributeContainer
```

## Overview

[`AttributeContainer`](/documentation/Foundation/AttributeContainer) provides a way to store attributes and their values outside of an attributed string. You use this type to initialize an instance of [`AttributedString`](/documentation/Foundation/AttributedString) with preset attributes, and to set, merge, or replace attributes in existing attributed strings.

## Topics

### Creating an Attribute Container

[`init()`](/documentation/Foundation/AttributeContainer/init())

Creates an empty attribute container.

[`init(_:including:)`](/documentation/Foundation/AttributeContainer/init(_:including:)-2mw0o)

Creates an attribute container from a dictionary and an attribute scope.

[`init(_:including:)`](/documentation/Foundation/AttributeContainer/init(_:including:)-28n0g)

Creates an attribute container from a dictionary and an attribute scope that a key path identifies.

[`init(_:)`](/documentation/Foundation/AttributeContainer/init(_:))

Creates an attribute container from a dictionary, using default attribute scopes.

### Accessing Attributes

[`subscript(_:)`](/documentation/Foundation/AttributeContainer/subscript(_:))

Returns the attribute that corresponds to a specified key.

[`subscript(dynamicMember:)`](/documentation/Foundation/AttributeContainer/subscript(dynamicMember:)-657oj)

Returns the attribute that corresponds to a specified key path.

[`subscript(dynamicMember:)`](/documentation/Foundation/AttributeContainer/subscript(dynamicMember:)-3jcvx)

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

[`subscript(dynamicMember:)`](/documentation/Foundation/AttributeContainer/subscript(dynamicMember:)-60ps5)

Returns a modified attribute container as part of building a chain of attributes.

[`subscript(dynamicMember:)`](/documentation/Foundation/AttributeContainer/subscript(dynamicMember:)-swift.type.subscript)

Returns a modified attribute container as part of building a chain of attributes, for use as a static method.

[`AttributedStringKey`](/documentation/Foundation/AttributedStringKey)

A type that defines an attribute’s name and type.

[`AttributeContainer.Builder`](/documentation/Foundation/AttributeContainer/Builder)

A type that iteratively builds attribute containers by setting attribute values.

### Modifying Attributes

[`merge(_:mergePolicy:)`](/documentation/Foundation/AttributeContainer/merge(_:mergePolicy:))

Merges the container’s attributes with those in another attribute container.

[`merging(_:mergePolicy:)`](/documentation/Foundation/AttributeContainer/merging(_:mergePolicy:))

Returns an attribute container by merging the container’s attributes with those in another attribute container.

[`AttributedString.AttributeMergePolicy`](/documentation/Foundation/AttributedString/AttributeMergePolicy)

An enumeration of behaviors to apply when merging attributes.

### Interoperating with Objective-C Attributes

[`ObjectiveCConvertibleAttributedStringKey`](/documentation/Foundation/ObjectiveCConvertibleAttributedStringKey)

A protocol that defines Objective-C interoperability with an attribute key’s value type.



---

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)