One Logo Pool Ball
Foundation · IOS API REFERENCE

IntegerFormatStyle.Attributed

struct · iOS 15.0+ · SDK 27.1

struct Attributed

A format style that converts integers into attributed strings. Use the ``IntegerFormatStyle/attributed`` modifier on a ``FloatingPointFormatStyle`` to create a format style of this type. The attributed strings that this format style creates contain attributes from the ``AttributeScopes/FoundationAttributes/NumberFormatAttributes`` attribute scope. Use these attributes to determine which runs of the attributed string represent different parts of the formatted value. The following example finds runs of the attributed string that represent different parts of a formatted currency, and adds additional attributes like ``AttributeScopes/SwiftUIAttributes/foregroundColor`` and ``AttributeScopes/FoundationAttributes/inlinePresentationIntent``. ```swift func attributedPrice(price: Decimal) -> AttributedString { var attributedPrice = price.formatted( .currency(code: "USD") .attributed) for run in attributedPrice.runs { if run.attributes.numberSymbol == .currency || run.attributes.numberSymbol == .decimalSeparator { attributedPrice[run.range].foregroundColor = .red } if run.attributes.numberPart == .integer || run.attributes.numberPart == .fraction { attributedPrice[run.range].inlinePresentationIntent = [.stronglyEmphasized] } } return attributedPrice } ``` User interface frameworks like SwiftUI can use these attributes when presenting the attributed string, as seen here: ![The currency value $1,234.56, with the dollar sign and decimal separator in red, and the digits in bold.](media-4099417)

Members (0)

This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.

Skipped declarations

No declarations were skipped in this snapshot.

All Foundation types →