StructureSwift
Duration.UnitsFormatStyle
iOS 16.0+
iPadOS 16.0+
Mac Catalyst 16.0+
macOS 13.0+
tvOS 16.0+
watchOS 9.0+
A
FormatStyle that displays a duration as a list of duration units, such as “2 hours, 43 minutes, 26 seconds” in English.struct UnitsFormatStyle
Topics
Structures
struct AttributedA format style to format a duration as an attributed string. Units in the string are annotated with thedurationFieldandmeasurementattribute keys and theDurationFieldAttributeandMeasurementAttributeattribute values.struct FractionalPartDisplayStrategySpecifies how a duration is displayed if it cannot be represented exactly with the allowed units.struct UnitUnits that a duration can be displayed as withUnitsFormatStyle.struct UnitWidthSpecifies the width of the unit and the spacing of the value and the unit.struct ZeroValueUnitsDisplayStrategySpecifies how zero value units are handled.
Initializers
init(allowedUnits: Set<Duration.UnitsFormatStyle.Unit>, width: Duration.UnitsFormatStyle.UnitWidth, maximumUnitCount: Int?, zeroValueUnits: Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy, valueLength: Int?, fractionalPart: Duration.UnitsFormatStyle.FractionalPartDisplayStrategy)Creates an instance using the provided specifications.init<ValueRange>(allowedUnits: Set<Duration.UnitsFormatStyle.Unit>, width: Duration.UnitsFormatStyle.UnitWidth, maximumUnitCount: Int?, zeroValueUnits: Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy, valueLengthLimits: ValueRange, fractionalPart: Duration.UnitsFormatStyle.FractionalPartDisplayStrategy)Creates an instance using the provided specifications.init(from: any Decoder) throws
Instance Properties
var allowedUnits: Set<Duration.UnitsFormatStyle.Unit>The units that may be included in the output string.var attributed: Duration.UnitsFormatStyle.AttributedReturns aDuration.UnitsFormatStyle.Attributedstyle to format a duration as an attributed string using the configuration of this format style. Units in the string are annotated with thedurationFieldandmeasurementattribute keys and theDurationFieldAttributeandMeasurementAttributeattribute values.var fractionalPartDisplay: Duration.UnitsFormatStyle.FractionalPartDisplayStrategyThe strategy for displaying a duration if it cannot be represented exactly with the allowed units.var locale: LocaleThe locale to use when formatting the duration.var maximumUnitCount: Int?The maximum number of time units to include in the output string.var unitWidth: Duration.UnitsFormatStyle.UnitWidthThe width of the unit and the spacing between the value and the unit.var valueLengthLimits: Range<Int>?The padding or truncating behavior of the unit value.var zeroValueUnitsDisplay: Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategyThe strategy for how zero-value units are handled.
Instance Methods
func format(Duration) -> StringCreates a locale-aware string representation from a duration value.func locale(Locale) -> Duration.UnitsFormatStyleA modifier to set the locale of the format style.
Default Implementations
Relationships
Conforms To
DiscreteFormatStyleFormatStyleSwift.CopyableSwift.DecodableSwift.EncodableSwift.EquatableSwift.EscapableSwift.HashableSwift.SendableSwift.SendableMetatype