---
title: attributed
framework: Foundation
role: symbol
role_heading: Instance Property
platforms: [iOS 15.0+, iPadOS 15.0+, Mac Catalyst 15.0+, macOS 12.0+, tvOS 15.0+, visionOS 1.0+, watchOS 8.0+]
path: foundation/date/formatstyle/3796283-attributed
---

# attributed

An attributed format style created from the date format style.

## Declaration

```swift
var attributed: Date.AttributedStyle { get }
```

## Discussion

Use a [Date.FormatStyle](../formatstyle.md) instance to customize the lexical representation of a date as a string. Use the format style’s [attributed](attributed-swift.property.md) property to customize the visual representation of the date as a string. Attributed strings can represent the subcomponent characters, words, and phrases of a string with a custom combination of font size, weight, and color.

For example, the function below uses a date format style to create a custom lexical representation of a date, then retrieves an attributed string representation of the same date and applies a visual emphasis to the year component of the date.

```swift
// Applies visual emphasis to the year component of a formatted attributed date string.
private func makeAttributedString() -> AttributedString {
    let date = Date()
    let formatStyle = Date.FormatStyle(date: .abbreviated, time: .standard)
    var attributedString = formatStyle.attributed.format(date)
    for run in attributedString.runs {
        if let dateFieldAttribute = run.attributes.foundation.dateField,
           dateFieldAttribute == .year {
            // When you find a year, change its attributes.
            attributedString[run.range].inlinePresentationIntent = [.emphasized, .stronglyEmphasized]
        }
    }
    return attributedString
}
```

The expression `formatStyle.attributed.format(date)` above creates an attributed string representation of the date. This assigns instances of the [AttributeScopes.FoundationAttributes.DateFieldAttribute](../../attributescopes/foundationattributes/datefieldattribute.md) to indicate ranges of the string that represent different date fields. The example then loops over the [runs](../../attributedstringprotocol/runs.md) of the attributed string to find any run with the [AttributeScopes.FoundationAttributes.DateFieldAttribute.Field.year](../../attributescopes/foundationattributes/datefieldattribute/field/year.md) attribute. When it finds one, it adds the [inlinePresentationIntent](../../attributescopes/foundationattributes/inlinepresentationintent.md) attributes [emphasized](../../inlinepresentationintent/emphasized.md) and [stronglyEmphasized](../../inlinepresentationintent/stronglyemphasized.md).

The runs of the resulting attributed string have the following attributes:

|  |  |
| --- | --- |
|  |  |
|  |  |
|  |  |
|  |  |
|  |  |
|  |  |
|  |  |

If you create a SwiftUI [Text](../../../swiftui/text.md) view with this attributed string, SwiftUI renders the combination of [emphasized](../../inlinepresentationintent/emphasized.md) and [stronglyEmphasized](../../inlinepresentationintent/stronglyemphasized.md) attributes as bold, italicized text, as seen in the following screenshot.

![]()

## See Also

### Applying Visual Attributes to Dates

- [Date.AttributedStyle](../attributedstyle.md)
