Why Foundation's new `FormatStyle` static func shorthand for Measurement has special case for `UnitTemparature`, while all others are generic to `UnitType`?

FormatStyle for Measurement has this special case for UnitTemparature:

https://developer.apple.com/documentation/foundation/formatstyle/3870095-measurement

All others is generic of UnitType:

https://developer.apple.com/documentation/foundation/formatstyle/3870096-measurement

Is there anyway to save an instance of Measurement.FormatStyle and apply it to any UnitType?

let formatStyle = Measurement.FormatStyle()   // <== how to create this?

// then use `formatStyle` on any Measurement:

let weight = Measurement(value: 1, unit: UnitMass.kilogram)
let length = Measurement(value: 2, unit: UnitLength.meter)
wight.formatted(formatStyle)
length.formatted(formatStyle)

No, because Measurement.FormatStyle is not a valid concrete type. Measurement<UnitLength>.FormatStyle and Measurement<UnitMass>.FormatStyle are distinct types and not interchangeable.

You wouldn't be able to use a value of type Measurement<UnitLength>.FormatStyle to format a mass.

2 Likes