Skip to content

StructureFoundationEssentials

AttributeContainer.Builder

iOS 15.0+ iPadOS 15.0+ Mac Catalyst 15.0+ macOS 12.0+ tvOS 15.0+ watchOS 8.0+
A type that iteratively builds attribute containers by setting attribute values.
struct Builder<T> where T : AttributedStringKey

Overview

The AttributeContainer.Builder type lets you build AttributeContainer instances by chaining together several attributes in one expression. The following example shows this approach:

// 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 attribute to the empty AttributeContainer. The builder’s callAsFunction(_:) returns a new AttributeContainer with this attribute set. Then the backgroundColor(.yellow) creates a second builder to modify the just-returned AttributeContainer by adding the backgroundColor attribute. The result is an AttributeContainer with both attributes set.

Topics

Instance Methods

Relationships

Conforms To

  • Swift.Sendable
  • Swift.SendableMetatype