Contents

AttributeContainer.Builder

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

Declaration

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

Calling Builder Functions

See Also

Accessing Attributes