UnitWidth
Specifies the width of the unit and the spacing of the value and the unit.
- iOS
- 16.0+
- macOS
- 13.0+
- tvOS
- 16.0+
- watchOS
- 9.0+
struct UnitWidth
Specifies the width of the unit and the spacing of the value and the unit.
struct UnitWidth
ss8DurationV30FoundationInternationalizationE16UnitsFormatStyleV9UnitWidthV
What are these?127Z6
import FoundationInternationalization
import Swift
struct UnitsFormatStyle
A FormatStyle
that displays a duration as a list of duration units, such as “2 hours, 43 minutes, 26 seconds” in English.
@frozen struct Duration
A representation of high precision time.
init(allowedUnits: Set<Duration.UnitsFormatStyle.Unit>, width: Duration.UnitsFormatStyle.UnitWidth, maximumUnitCount: Int? = nil, zeroValueUnits: Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy = .hide, valueLength: Int? = nil, fractionalPart: Duration.UnitsFormatStyle.FractionalPartDisplayStrategy = .hide)
Creates an instance using the provided specifications.
init<ValueRange>(allowedUnits: Set<Duration.UnitsFormatStyle.Unit>, width: Duration.UnitsFormatStyle.UnitWidth, maximumUnitCount: Int? = nil, zeroValueUnits: Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy = .hide, valueLengthLimits: ValueRange, fractionalPart: Duration.UnitsFormatStyle.FractionalPartDisplayStrategy = .hide) where ValueRange : RangeExpression, ValueRange.Bound == Int
Creates an instance using the provided specifications.
init(from decoder: any Decoder) throws
var allowedUnits: Set<Duration.UnitsFormatStyle.Unit>
The units that may be included in the output string.
var attributed: Duration.UnitsFormatStyle.Attributed { get }
Returns a Duration.UnitsFormatStyle.Attributed
style to format a duration as an attributed string using the configuration of this format style. Units in the string are annotated with the durationField
and measurement
attribute keys and the DurationFieldAttribute
and MeasurementAttribute
attribute values.
var fractionalPartDisplay: Duration.UnitsFormatStyle.FractionalPartDisplayStrategy
The strategy for displaying a duration if it cannot be represented exactly with the allowed units.
var locale: Locale
The 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.UnitWidth
The 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.ZeroValueUnitsDisplayStrategy
The strategy for how zero-value units are handled.
func discreteInput(after input: Duration) -> Duration?
func discreteInput(before input: Duration) -> Duration?
func format(_ duration: Duration) -> String
Creates a locale-aware string representation from a duration value.
func locale(_ locale: Locale) -> Duration.UnitsFormatStyle
A modifier to set the locale of the format style.
@dynamicMemberLookup struct 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.
struct FractionalPartDisplayStrategy
Specifies how a duration is displayed if it cannot be represented exactly with the allowed units.
struct Unit
Units that a duration can be displayed as with UnitsFormatStyle
.
struct ZeroValueUnitsDisplayStrategy
Specifies how zero value units are handled.
protocol Decodable
A type that can decode itself from an external representation.
protocol Encodable
A type that can encode itself to an external representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol Sendable
init(from decoder: any Decoder) throws
static var abbreviated: Duration.UnitsFormatStyle.UnitWidth { get }
Shows the abbreviated unit name, such as “3 hr” for a 3-hour duration in the en_US locale.
static var condensedAbbreviated: Duration.UnitsFormatStyle.UnitWidth { get }
Shows the abbreviated unit name with a condensed space between the value and unit, such as “3hr” for a 3-hour duration in the en_US locale.
static var narrow: Duration.UnitsFormatStyle.UnitWidth { get }
Shows the shortest unit name, such as “3h” for a 3-hour duration in the en_US locale.
static var wide: Duration.UnitsFormatStyle.UnitWidth { get }
Shows the full unit name, such as “3 hours” for a 3-hour duration in the en_US locale.
func encode(to encoder: any Encoder) throws
func hash(into hasher: inout Hasher)
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.