A format style that provides string representations of byte counts.
The following example creates an `Int` representing 1,024 bytes, and then formats it as an
expression of memory storage, with the default byte count format style.
```swift
let count: Int64 = 1024
let formatted = count.formatted(.byteCount(style: .memory)) // "1 kB"
```
You can also customize a byte count format style, and use this to format one or more `Int64`
instances. The following example creates a format style to only use kilobyte units, and to
spell out the exact byte count of the measurement.
```swift
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"]
```
Members (15)
get · iOS 15.0+
includesActualByteCount
TypeScript
get includesActualByteCount(): boolean
Swift declaration
var includesActualByteCount: Bool { get set }
A Boolean value that indicates whether the format style should include the exact byte count, in addition to expressing it in terms of units.
set · iOS 15.0+
includesActualByteCount
TypeScript
set includesActualByteCount(value: boolean)
Swift declaration
var includesActualByteCount: Bool { get set }
A Boolean value that indicates whether the format style should include the exact byte count, in addition to expressing it in terms of units.
get · iOS 15.0+
attributed
TypeScript
get attributed(): ByteCountFormatStyle_Attributed
Swift declaration
var attributed: ByteCountFormatStyle.Attributed
An attributed format style based on the byte count format style.
set · iOS 15.0+
attributed
TypeScript
set attributed(value: ByteCountFormatStyle_Attributed)
Swift declaration
var attributed: ByteCountFormatStyle.Attributed
An attributed format style based on the byte count format style.
get · iOS 15.0+
allowedUnits
TypeScript
get allowedUnits(): ByteCountFormatStyle_Units
Swift declaration
var allowedUnits: ByteCountFormatStyle.Units { get set }
The units the format style can use to express the byte count.
set · iOS 15.0+
allowedUnits
TypeScript
set allowedUnits(value: ByteCountFormatStyle_Units)
Swift declaration
var allowedUnits: ByteCountFormatStyle.Units { get set }
The units the format style can use to express the byte count.
get · iOS 15.0+
spellsOutZero
TypeScript
get spellsOutZero(): boolean
Swift declaration
var spellsOutZero: Bool { get set }
A Boolean value that indicates whether the format style should spell out zero-byte values as text.
set · iOS 15.0+
spellsOutZero
TypeScript
set spellsOutZero(value: boolean)
Swift declaration
var spellsOutZero: Bool { get set }
A Boolean value that indicates whether the format style should spell out zero-byte values as text.