<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/ByteCountFormatStyle",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation20ByteCountFormatStyleV"
  },
  "title" : "ByteCountFormatStyle"
}
-->

# ByteCountFormatStyle

A format style that provides string representations of byte counts.

```
struct ByteCountFormatStyle
```

## Overview

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 <doc://com.apple.documentation/documentation/Swift/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"]
```

## Topics

### Creating a byte count style

[`init(style:allowedUnits:spellsOutZero:includesActualByteCount:locale:)`](/documentation/Foundation/ByteCountFormatStyle/init(style:allowedUnits:spellsOutZero:includesActualByteCount:locale:))

Initializes a byte count format style.

[`ByteCountFormatStyle.Units`](/documentation/Foundation/ByteCountFormatStyle/Units)

The units to use when formatting a byte count, such as kilobytes or gigabytes.

### Formatting byte count values

[`format(_:)`](/documentation/Foundation/ByteCountFormatStyle/format(_:))

Formats a numeric byte count, using this style.

### Customizing style behavior

[`style`](/documentation/Foundation/ByteCountFormatStyle/style-swift.property)

The semantic style the format style uses to represent a byte count value.

[`ByteCountFormatStyle.Style`](/documentation/Foundation/ByteCountFormatStyle/Style-swift.enum)

The semantic style to use when formatting a byte count value.

### Accessing style properties

[`allowedUnits`](/documentation/Foundation/ByteCountFormatStyle/allowedUnits)

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

[`ByteCountFormatStyle.Units`](/documentation/Foundation/ByteCountFormatStyle/Units)

The units to use when formatting a byte count, such as kilobytes or gigabytes.

[`spellsOutZero`](/documentation/Foundation/ByteCountFormatStyle/spellsOutZero)

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

[`includesActualByteCount`](/documentation/Foundation/ByteCountFormatStyle/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.

[`locale`](/documentation/Foundation/ByteCountFormatStyle/locale)

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

### Modifying style locale

[`locale(_:)`](/documentation/Foundation/ByteCountFormatStyle/locale(_:))

Modifies the format style to use the specified locale.

### Applying currency styles

### Applying measurement styles

### Applying list styles

### Creating attributed strings

[`attributed`](/documentation/Foundation/ByteCountFormatStyle/attributed-swift.property)

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

[`ByteCountFormatStyle.Attributed`](/documentation/Foundation/ByteCountFormatStyle/Attributed-swift.struct)

A format style that converts byte counts into attributed strings.

### Supporting types



---

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)