format(_:)
Formats a numeric byte count, using this style.
Declaration
func format(_ value: Int64) -> StringParameters
- value:
The 64-bit byte count to format.
Return Value
A formatted representation of value, formatted according to the style’s configuration.
Discussion
Use this method when you want to create a single style instance, and then use it to format multiple values. The following example creates a ByteCountFormatStyle to format values as kilobyte counts, then applies this style to an array of Int64 values.
let style = ByteCountFormatStyle(style: .memory,
allowedUnits: [.kb],
spellsOutZero: true,
includesActualByteCount: false,
locale: Locale(identifier: "en_US"))
let counts: [Int64] = [0, 1024, 2048, 4096, 8192, 16384, 32768, 65536]
let formatted = counts.map ( {style.format($0) } ) // ["Zero kB", "1 kB", "2 kB", "4 kB", "8 kB", "16 kB", "32 kB", "64 kB"]
To format a single integer, use the BinaryInteger instance method formatted(_:), passing in an instance of IntegerFormatStyle, or formatted() to use a default style.