---
title: Measurement.FormatStyle.ByteCount
framework: foundation
role: symbol
role_heading: Structure
path: foundation/measurement/formatstyle/bytecount
---

# Measurement.FormatStyle.ByteCount

A format style that provides string representations of byte counts, expressed as measurements of information storage.

## Declaration

```swift
struct ByteCount
```

## Overview

Overview Use this style with a Measurement whose unit type is UnitInformationStorage to format byte counts according to locale conventions. The following example creates a measurement of 1,024 bytes, and then formats it as an expression of memory storage, with the default byte count format style: let count = Measurement(value: 1024, unit: UnitInformationStorage.bytes) 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 Measurement instances. The following example creates a format style to only use kilobyte units, and to spell out the exact byte count of the measurement. let count = Measurement(value: 1024, unit: UnitInformationStorage.bytes) let style = Measurement.FormatStyle.ByteCount(style: .memory,                                               allowedUnits: .kb,                                               spellsOutZero: true,                                               includesActualByteCount: true,                                               locale: Locale(identifier: "en_US")) let customFormatted = style.format(count) // "1 kB (1,024 bytes)"

## Topics

### Creating a byte count style

- [init(style:allowedUnits:spellsOutZero:includesActualByteCount:locale:)](foundation/measurement/formatstyle/bytecount/init(style:allowedunits:spellsoutzero:includesactualbytecount:locale:).md)

### Formatting byte count measurements

- [format(_:)](foundation/measurement/formatstyle/bytecount/format(_:).md)

### Accessing style properties

- [allowedUnits](foundation/measurement/formatstyle/bytecount/allowedunits.md)
- [Measurement.FormatStyle.ByteCount.Units](foundation/measurement/formatstyle/bytecount/units.md)
- [spellsOutZero](foundation/measurement/formatstyle/bytecount/spellsoutzero.md)
- [includesActualByteCount](foundation/measurement/formatstyle/bytecount/includesactualbytecount.md)
- [style](foundation/measurement/formatstyle/bytecount/style-swift.property.md)
- [Measurement.FormatStyle.ByteCount.Style](foundation/measurement/formatstyle/bytecount/style-swift.typealias.md)
- [locale](foundation/measurement/formatstyle/bytecount/locale.md)

### Modifying style locale

- [locale(_:)](foundation/measurement/formatstyle/bytecount/locale(_:).md)

### Creating attributed strings

- [attributed](foundation/measurement/formatstyle/bytecount/attributed.md)
- [Measurement.AttributedStyle.ByteCount](foundation/measurement/attributedstyle/bytecount.md)

## Relationships

### Conforms To

- [Decodable](swift/decodable.md)
- [Encodable](swift/encodable.md)
- [Equatable](swift/equatable.md)
- [FormatStyle](foundation/formatstyle.md)
- [Hashable](swift/hashable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Applying byte-count styles

- [byteCount(style:allowedUnits:spellsOutZero:includesActualByteCount:)](foundation/formatstyle/bytecount(style:allowedunits:spellsoutzero:includesactualbytecount:)-59ep0.md)
- [ByteCountFormatStyle](foundation/bytecountformatstyle.md)
- [byteCount(style:allowedUnits:spellsOutZero:includesActualByteCount:)](foundation/formatstyle/bytecount(style:allowedunits:spellsoutzero:includesactualbytecount:)-ev0u.md)
