Skip to content

Type MethodFoundationEssentials

units(allowed:width:maximumUnitCount:zeroValueUnits:valueLength:fractionalPart:)

iOS 16.0+ iPadOS 16.0+ Mac Catalyst 16.0+ macOS 13.0+ tvOS 16.0+ watchOS 9.0+
A factory function to create a units format style to format a duration.
static func units(allowed units: Set<Duration.UnitsFormatStyle.Unit> = [.hours, .minutes, .seconds], width: Duration.UnitsFormatStyle.UnitWidth = .abbreviated, maximumUnitCount: Int? = nil, zeroValueUnits: Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy = .hide, valueLength: Int? = nil, fractionalPart: Duration.UnitsFormatStyle.FractionalPartDisplayStrategy = .hide) -> Self

Parameters

units

The units that may be included in the output string.

width

The width of the unit and the spacing between the value and the unit.

maximumUnitCount

The maximum number of time units to include in the output string.

zeroValueUnits

The strategy for how zero-value units are handled.

valueLength

The padding or truncating behavior of the unit value.

fractionalPart

The strategy for displaying a duration if it cannot be represented exactly with the allowed units.

Return Value

A format style to format a duration.