<!--
{
  "availability" : [
    "iOS: 15.0.0 - 18.0.0",
    "iPadOS: 15.0.0 - 18.0.0",
    "macCatalyst: 15.0.0 - 18.0.0",
    "macOS: 12.0.0 - 15.0.0",
    "tvOS: 15.0.0 - 18.0.0",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 - 11.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Date/FormatStyle/attributed-swift.property",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation4DateV11FormatStyleV10attributedAC010AttributedD0Vvp"
  },
  "title" : "attributed"
}
-->

# attributed

An attributed format style created from the date format style.

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

## Discussion

Use a [`Date.FormatStyle`](/documentation/Foundation/Date/FormatStyle) instance to customize the lexical representation of a date as a string. Use the format style’s [`attributed`](/documentation/Foundation/Date/FormatStyle/attributed-swift.property) 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`](/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute) to indicate ranges of the string that represent different date fields. The example then loops over the [`runs`](/documentation/Foundation/AttributedStringProtocol/runs) of the attributed string to find any run with the [`AttributeScopes.FoundationAttributes.DateFieldAttribute.Field.year`](/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/year) attribute. When it finds one, it adds the [`inlinePresentationIntent`](/documentation/Foundation/AttributeScopes/FoundationAttributes/inlinePresentationIntent) attributes [`emphasized`](/documentation/Foundation/InlinePresentationIntent/emphasized) and [`stronglyEmphasized`](/documentation/Foundation/InlinePresentationIntent/stronglyEmphasized).

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

|Run Text|Attributes                                                                                                                                                                                                                                                                                                                                         |
|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|Mar     |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/month``                                                                                                                                                                                                                        |
|15      |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/day``                                                                                                                                                                                                                          |
|2022    |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/year`` ![](spacer) ``doc://com.apple.foundation/documentation/Foundation/InlinePresentationIntent/emphasized``  ![](spacer) ``doc://com.apple.foundation/documentation/Foundation/InlinePresentationIntent/stronglyEmphasized``|
|10      |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/hour``                                                                                                                                                                                                                         |
|06      |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/minute``                                                                                                                                                                                                                       |
|46      |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/second``                                                                                                                                                                                                                       |
|AM      |``doc://com.apple.foundation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute/Field/amPM``                                                                                                                                                                                                                         |

If you create a SwiftUI <doc://com.apple.documentation/documentation/SwiftUI/Text> view with this attributed string, SwiftUI renders the combination of [`emphasized`](/documentation/Foundation/InlinePresentationIntent/emphasized) and [`stronglyEmphasized`](/documentation/Foundation/InlinePresentationIntent/stronglyEmphasized) attributes as bold, italicized text, as seen in the following screenshot.

![A macOS window with a text view showing the current date and time. The year is displayed in bold, italicized text.](images/com.apple.foundation/media-3957718@2x.png)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)