<!--
{
  "availability" : [
    "iOS: 6.0.0 -",
    "iPadOS: 6.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.8.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/ByteCountFormatter",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSByteCountFormatter"
  },
  "title" : "ByteCountFormatter"
}
-->

# ByteCountFormatter

A formatter that converts a byte count value into a localized description that is formatted with the appropriate byte modifier (KB, MB, GB and so on).

```
class ByteCountFormatter
```

## Overview> Tip:
> In Swift, you can use ``doc://com.apple.foundation/documentation/Foundation/ByteCountFormatStyle`` or ``doc://com.apple.foundation/documentation/Foundation/Measurement/FormatStyle/ByteCount`` rather than ``doc://com.apple.foundation/documentation/Foundation/ByteCountFormatter``. The ``doc://com.apple.foundation/documentation/Foundation/FormatStyle`` API offers a declarative idiom for customizing the formatting of various types. Also, Foundation caches identical ``doc://com.apple.foundation/documentation/Foundation/FormatStyle`` instances, so you don’t need to pass them around your app, or risk wasting memory with duplicate formatters.

## Topics

### Creating Strings from Byte Count

[`string(fromByteCount:countStyle:)`](/documentation/Foundation/ByteCountFormatter/string(fromByteCount:countStyle:))

Converts a byte count into the specified string format without creating an `NSNumber` object.

[`string(fromByteCount:)`](/documentation/Foundation/ByteCountFormatter/string(fromByteCount:))

Converts a byte count into a string without creating an `NSNumber` object.

### Setting Formatting Styles

[`formattingContext`](/documentation/Foundation/ByteCountFormatter/formattingContext)

Specify the formatting context for the formatted string.

[`countStyle`](/documentation/Foundation/ByteCountFormatter/countStyle-swift.property)

Specify the number of bytes to be used for kilobytes.

[`allowsNonnumericFormatting`](/documentation/Foundation/ByteCountFormatter/allowsNonnumericFormatting)

Determines whether to allow more natural display of some values.

[`includesActualByteCount`](/documentation/Foundation/ByteCountFormatter/includesActualByteCount)

Determines whether to include the number of bytes after the formatted string.

[`isAdaptive`](/documentation/Foundation/ByteCountFormatter/isAdaptive)

Determines the display style of the size representation.

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

Specify the units that can be used in the output.

[`includesCount`](/documentation/Foundation/ByteCountFormatter/includesCount)

Determines whether to include the count in the resulting formatted string.

[`includesUnit`](/documentation/Foundation/ByteCountFormatter/includesUnit)

Determines whether to include the units in the resulting formatted string.

[`zeroPadsFractionDigits`](/documentation/Foundation/ByteCountFormatter/zeroPadsFractionDigits)

Determines whether to zero pad fraction digits so a consistent number of characters is displayed in a representation.

### Constants

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

Specifies the units appropriate for the formatter to display. Specifying any units explicitly causes just those units to be used in showing the number.

[`ByteCountFormatter.CountStyle`](/documentation/Foundation/ByteCountFormatter/CountStyle-swift.enum)

Specifies display of file or storage byte counts. The display style is platform specific.



---

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)