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

# AttributeContainer.Builder

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

```
struct Builder<T> where T : AttributedStringKey
```

## Overview

The [`AttributeContainer.Builder`](/documentation/Foundation/AttributeContainer/Builder) type lets you build [`AttributeContainer`](/documentation/Foundation/AttributeContainer) instances by chaining together several attributes in one expression. The following example shows this approach:

```swift
// An attribute container with the link and backgroundColor attributes.
let myContainer = AttributeContainer().link(myURL).backgroundColor(.yellow)
```

The first part of this expression, `AttributeContainer().link(URL(myURL))`, creates a builder to apply the [`link`](/documentation/Foundation/AttributeScopes/FoundationAttributes/link) attribute to the empty [`AttributeContainer`](/documentation/Foundation/AttributeContainer). The builder’s [`callAsFunction(_:)`](/documentation/Foundation/AttributeContainer/Builder/callAsFunction(_:)) returns a new [`AttributeContainer`](/documentation/Foundation/AttributeContainer) with this attribute set. Then the `backgroundColor(.yellow)` creates a second builder to modify the just-returned [`AttributeContainer`](/documentation/Foundation/AttributeContainer) by adding the [`backgroundColor`](/documentation/Foundation/AttributeScopes/SwiftUIAttributes/backgroundColor) attribute. The result is an [`AttributeContainer`](/documentation/Foundation/AttributeContainer) with both attributes set.

## Topics

### Calling Builder Functions

[`func callAsFunction(T.Value) -> AttributeContainer`](/documentation/Foundation/AttributeContainer/Builder/callAsFunction(_:))

Builds an attribute container by setting an attribute and returning a modified attribute container.

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

---

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)