<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Measurement/FormatStyle/ByteCount",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation11MeasurementVAASo11NSDimensionCRbzrlE11FormatStyleVAASo24NSUnitInformationStorageCRszrlE9ByteCountV"
  },
  "title" : "Measurement.FormatStyle.ByteCount"
}
-->

# Measurement.FormatStyle.ByteCount

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

```
struct ByteCount
```

## Overview

Use this style with a [`Measurement`](/documentation/Foundation/Measurement) whose unit type is [`UnitInformationStorage`](/documentation/Foundation/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:

```swift
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`](/documentation/Foundation/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.

```swift
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: Measurement<UnitType>.FormatStyle.ByteCount.Style, allowedUnits: Measurement<UnitType>.FormatStyle.ByteCount.Units, spellsOutZero: Bool, includesActualByteCount: Bool, locale: Locale)`](/documentation/Foundation/Measurement/FormatStyle/ByteCount/init(style:allowedUnits:spellsOutZero:includesActualByteCount:locale:))

Initializes a byte count format style.

### Formatting byte count measurements

[`func format(Measurement<UnitInformationStorage>) -> String`](/documentation/Foundation/Measurement/FormatStyle/ByteCount/format(_:))

Formats a byte count measurment, using this style.

### Accessing style properties

[`var allowedUnits: Measurement<UnitInformationStorage>.FormatStyle.ByteCount.Units`](/documentation/Foundation/Measurement/FormatStyle/ByteCount/allowedUnits)

The units the format style can use to express the byte count.

[`typealias Units`](/documentation/Foundation/Measurement/FormatStyle/ByteCount/Units)

The type the measurement format style uses to represent byte-counting units.

[`var spellsOutZero: Bool`](/documentation/Foundation/Measurement/FormatStyle/ByteCount/spellsOutZero)

A Boolean value that indicates whether the format style should spell out zero-byte values as text.

[`var includesActualByteCount: Bool`](/documentation/Foundation/Measurement/FormatStyle/ByteCount/includesActualByteCount)

A Boolean value that indicates whether the format style should include the exact byte count, in addition to expressing it in terms of units.

[`var style: Measurement<UnitInformationStorage>.FormatStyle.ByteCount.Style`](/documentation/Foundation/Measurement/FormatStyle/ByteCount/style-swift.property)

The style of byte count to express, such as memory or file system storage.

[`typealias Style`](/documentation/Foundation/Measurement/FormatStyle/ByteCount/Style-swift.typealias)

The type used to represent the style of the formatted byte count.

[`var locale: Locale`](/documentation/Foundation/Measurement/FormatStyle/ByteCount/locale)

The locale to use to format the numeric part of the byte count.

### Modifying style locale

[`func locale(Locale) -> Measurement<UnitType>.FormatStyle.ByteCount`](/documentation/Foundation/Measurement/FormatStyle/ByteCount/locale(_:))

Modifies the format style to use the specified locale.

### Applying currency styles

### Applying measurement styles

### Applying list styles

### Creating attributed strings

[`var attributed: Measurement<UnitInformationStorage>.AttributedStyle.ByteCount`](/documentation/Foundation/Measurement/FormatStyle/ByteCount/attributed)

An attributed format style based on the byte count format style.

[`struct ByteCount`](/documentation/Foundation/Measurement/AttributedStyle/ByteCount)

A format style that converts byte counts into attributed strings.

### Supporting types

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`Equatable`](/documentation/Swift/Equatable)

[`Decodable`](/documentation/Swift/Decodable)

[`FormatStyle`](/documentation/Foundation/FormatStyle)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Hashable`](/documentation/Swift/Hashable)

[`Encodable`](/documentation/Swift/Encodable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)