One Logo Pool Ball
Foundation · IOS API REFERENCE

AttributeContainer

struct · iOS 15.0+ · SDK 27.1

@dynamicMemberLookup struct AttributeContainer

A container for attribute keys and values. ``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`` with preset attributes, and to set, merge, or replace attributes in existing attributed strings.

Members (9)

get · iOS 15.0+

description

TypeScript
get description(): string
Swift declaration
var description: String { get }

A textual representation of this instance. Calling this property directly is discouraged. Instead, convert an instance of any type to a string by using the `String(describing:)` initializer. This initializer works with any type, and uses the custom `description` property for types that conform to `CustomStringConvertible`: struct Point: CustomStringConvertible { let x: Int, y: Int var description: String { return "(\(x), \(y))" } } let p = Point(x: 21, y: 30) let s = String(describing: p) print(s) // Prints "(21, 30)" The conversion of `p` to a string in the assignment to `s` uses the `Point` type's `description` property.

init · iOS 15.0+

init

TypeScript
static initFromConfiguration(decoder: SDKHandle, configuration: AttributeScopeCodableConfiguration): AttributeContainer
Swift declaration
init(from decoder: any Decoder, configuration: AttributeScopeCodableConfiguration) throws

Creates a new instance by retrieving the instance's data from the specified decoder with help from the provided configuration. - Parameters: - decoder: The decoder to read data from. - configuration: A decoding configuration instance that provides additional information necessary for decoding.

method · iOS 15.0+

merge

TypeScript
merge(other: AttributeContainer, mergePolicy?: AttributedString_AttributeMergePolicy): void
Swift declaration
mutating func merge(_ other: AttributeContainer, mergePolicy: AttributedString.AttributeMergePolicy = .keepNew)

Merges the container's attributes with those in another attribute container. - Parameters: - other: The attribute container with the attributes to merge. - mergePolicy: A policy to use when resolving conflicts between this string's attributes and those in `other`.

method · iOS 15.0+

encode

TypeScript
encode(encoder: SDKHandle, configuration: AttributeScopeCodableConfiguration): void
Swift declaration
func encode(to encoder: any Encoder, configuration: AttributeScopeCodableConfiguration) throws

Encodes the value into the specified encoder with help from the provided configuration. - Parameters: - encoder: The encoder to write data to. - configuration: An encoding configuration instance that provides additional information necessary for encoding.

method · iOS 26.0+

filter

TypeScript
filterRunBoundaries(runBoundaries?: (AttributedString_AttributeRunBoundaries) | null): AttributeContainer
Swift declaration
func filter(runBoundaries: AttributedString.AttributeRunBoundaries?) -> AttributeContainer

Returns a copy of the attribute container with only attributes that have the provided run boundaries. - Parameter runBoundaries: The required `runBoundaries` value of the filtered attributes. If `nil` is provided, only attributes not bound to any specific boundary will be returned. - Returns: A copy of the attribute container with only attributes whose `runBoundaries` property matches the provided value.

method · iOS 26.0+

filter

TypeScript
filterInheritedByAddedText(inheritedByAddedText: boolean): AttributeContainer
Swift declaration
func filter(inheritedByAddedText: Bool) -> AttributeContainer

Returns a copy of the attribute container with only attributes that specify the provided inheritance behavior. - Parameter inheritedByAddedText: An `inheritedByAddedText` value to filter. Attributes matching this value are included in the returned container. - Returns: A copy of the attribute container with only attributes whose `inheritedByAddedText` property matches the provided value.

method · iOS 15.0+

merging

TypeScript
merging(other: AttributeContainer, mergePolicy?: AttributedString_AttributeMergePolicy): AttributeContainer
Swift declaration
func merging(_ other: AttributeContainer, mergePolicy: AttributedString.AttributeMergePolicy = .keepNew) -> AttributeContainer

Returns an attribute container by merging the container's attributes with those in another attribute container. - Parameters: - other: The attribute container with the attributes to merge. - mergePolicy: A policy to use when resolving conflicts between this string's attributes and those in `other`. - Returns: An attribute container created by merging the source container's attributes with those in another attribute container.

init · iOS 15.0+

init

TypeScript
static init(): AttributeContainer
Swift declaration
init()

Creates an empty attribute container.

init · iOS 15.0+

init

TypeScript
static init57744(dictionary: NativeMap<NSAttributedString_Key, unknown>): AttributeContainer
Swift declaration
init(_ dictionary: [NSAttributedString.Key : Any])

Creates an attribute container from a dictionary, using default attribute scopes. - Parameter dictionary: A dictionary of attribute keys and their values. This initializer includes all attribute scopes defined by the SDK, such as `FoundationAttributes`, `SwiftUIAttributes`, and `AccessibilityAttributes`. To use third-party attribute scopes, use the initializers ``AttributeContainer/init(_:including:)-2mw0o`` and ``AttributeContainer/init(_:including:)-28n0g``.

Skipped declarations

6 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

AttributeContainer.subscript(_:)

Passing a Swift type itself is not supported.

AttributeContainer.subscript(dynamicMember:)

This declaration needs Swift generic type arguments. (no canonical witness for K)

AttributeContainer.subscript(dynamicMember:)

Passing a Swift type itself is not supported.

AttributeContainer.subscript(dynamicMember:)

This declaration needs Swift generic type arguments. (no canonical witness for K)

AttributeContainer.init(_:including:)

Passing a Swift type itself is not supported.

AttributeContainer.init(_:including:)

Passing a Swift type itself is not supported.

All Foundation types →