alobaili
(Abdulaziz Alobaili)
September 9, 2026, 1:37pm
1
Consider the following:
let measurement = Measurement(value: 1000, unit: UnitInformationStorage.megabytes)
I can format it in the following ways:
measurement.formatted(.byteCount(style: .file)) // 1 GB
measurement.formatted(.measurement(width: .wide)) // 1,000 megabytes
I want the automatic scaling of .byteCount(style:) with the ability to control the width of the unit that .measurement(width:) provides. Is that possible?
The final desired output I want for formatting measurement is 1 gigabyte.
I played around with FormatStyle APIs, but couldn't achieve the output I want.
Nan
(Nan Yang)
September 11, 2026, 2:48am
2
One possible way is to convert its unit to gigabytes first:
measurement
.converted(to: .gigabytes)
.formatted(.measurement(width: .wide))
alobaili
(Abdulaziz Alobaili)
September 11, 2026, 9:06am
3
.byteCount provides the automatic scaling to the appropriate unit based on the value. For example it could show “GB”, “MB”, “kB”, etc.
I want this automatic behavior but with the option to display the unit as “gigabytes”, “megabytes”, “kilobytes” that width: .wide provides.
in your example above can I pass a hypothetical .converted(to: .automatic) or .default that give the same behavior as ByteCountFormatStyle?