Contents

Duration.TimeFormatStyle.Attributed

A format style that formats durations as attributed strings.

Declaration

@dynamicMemberLookup struct Attributed

Overview

Apply the Duration.TimeFormatStyle.Attributed property to a configured Duration.TimeFormatStyle to produce an instance of this style. You can then format a duration with this style to create a formatted AttributedString. The formatted attributed string contains instances of AttributeScopes.FoundationAttributes.DateFieldAttribute 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.TimeFormatStyle(pattern: .hourMinuteSecond).attributed
let attributedDuration = duration.formatted(style)

The resulting attributedDuration, representing the string 1:10:32 contains the following runs:

Run

Attributes

1

Foundation.DurationFormatAttribute = hours

:

None

10

Foundation.DurationFormatAttribute = minutes

:

None

32

Foundation.DurationFormatAttribute = seconds

Topics

Formatting a duration

Working with locales

Instance Methods

Subscripts

See Also

Formatting a duration as an attributed string