<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Duration/UnitsFormatStyle/attributed-swift.property",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s8DurationV10FoundationE16UnitsFormatStyleV10attributedAE10AttributedVvp"
  },
  "title" : "attributed"
}
-->

# attributed

A property that formats the duration as an attributed string.

```
var attributed: Duration.UnitsFormatStyle.Attributed { get }
```

## Discussion

Apply the `attributed` property to a configured [`Duration.UnitsFormatStyle`](/documentation/Swift/Duration/UnitsFormatStyle) to produce an [`Duration.UnitsFormatStyle.Attributed`](/documentation/Swift/Duration/UnitsFormatStyle/Attributed-swift.struct) style. You can then format a duration with this style to create a formatted   <doc://com.apple.documentation/documentation/Foundation/AttributedString>. The formatted attributed string contains instances of <doc://com.apple.documentation/documentation/Foundation/AttributeScopes/FoundationAttributes/DateFieldAttribute> and <doc://com.apple.documentation/documentation/Foundation/AttributeScopes/FoundationAttributes/MeasurementAttribute> for runs with formatted durations.

The following example formats a duration as an attributed string:

```
let duration = Duration.seconds(70 * 60 + 32) +
    Duration.milliseconds(400)
let style = Duration.UnitsFormatStyle(allowedUnits: [.hours, .minutes, .seconds],
                                      width: .abbreviated).attributed
let attributedDuration = duration.formatted(style)
```

The resulting `attributedDuration`, representing the string `1 hr, 10 min, 32 sec` contains the following runs:

|Run    |Attributes                                                                               |
|-------|-----------------------------------------------------------------------------------------|
|`1`    |`Foundation.MeasurementAttribute = value`, `Foundation.DurationFormatAttribute = hours`  |
|(space)|`Foundation.DurationFormatAttribute = hours`                                             |
|`hr`   |`Foundation.DurationFormatAttribute = hours`, `Foundation.MeasurementAttribute = unit`   |
|`,  `  |None                                                                                     |
|`10`   |`Foundation.MeasurementAttribute = value`, `Foundation.DurationFormatAttribute = minutes`|
|(space)|`Foundation.DurationFormatAttribute = minutes`                                           |
|`min`  |`Foundation.DurationFormatAttribute = minutes`, `Foundation.MeasurementAttribute = unit` |
|`,  `  |None                                                                                     |
|`32`   |`Foundation.MeasurementAttribute = value`, `Foundation.DurationFormatAttribute = seconds`|
|(space)|`Foundation.DurationFormatAttribute = seconds`                                           |
|`sec`  |`Foundation.DurationFormatAttribute = seconds`, `Foundation.MeasurementAttribute = unit` |

---

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)