Attributed

A format style to format a duration as an attributed string. Units in the string are annotated with the durationField and measurement attribute keys and the DurationFieldAttribute and MeasurementAttribute attribute values.

iOS
16.0+
macOS
13.0+
tvOS
16.0+
watchOS
9.0+
@dynamicMemberLookup struct Attributed

You can use Duration.UnitsFormatStyle to configure the style, and create an Attributed format with its public var attributed: Attributed

For example, formatting a duration of 2 hours, 43 minutes, 26.25 second in en_US locale yeilds the following conceptually

2 { durationField: .hours, component: .value }
hours { durationField: .hours, component: .unit }
, { nil }
43 { durationField: .minutes, component: .value }
minutes { durationField: .minutes, component: .unit }
, { nil }
26.25 { durationField: .seconds, component: .value }
seconds { durationField: .seconds, component: .unit }