---
title: ByteCountFormatter
framework: foundation
role: symbol
role_heading: Class
path: foundation/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).

## Declaration

```swift
class ByteCountFormatter
```

## Overview

Overview tip: In Swift, you can use ByteCountFormatStyle or Measurement.FormatStyle.ByteCount rather than ByteCountFormatter. The FormatStyle API offers a declarative idiom for customizing the formatting of various types. Also, Foundation caches identical 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:)](foundation/bytecountformatter/string(frombytecount:countstyle:).md)
- [string(fromByteCount:)](foundation/bytecountformatter/string(frombytecount:).md)

### Setting Formatting Styles

- [formattingContext](foundation/bytecountformatter/formattingcontext.md)
- [countStyle](foundation/bytecountformatter/countstyle-swift.property.md)
- [allowsNonnumericFormatting](foundation/bytecountformatter/allowsnonnumericformatting.md)
- [includesActualByteCount](foundation/bytecountformatter/includesactualbytecount.md)
- [isAdaptive](foundation/bytecountformatter/isadaptive.md)
- [allowedUnits](foundation/bytecountformatter/allowedunits.md)
- [includesCount](foundation/bytecountformatter/includescount.md)
- [includesUnit](foundation/bytecountformatter/includesunit.md)
- [zeroPadsFractionDigits](foundation/bytecountformatter/zeropadsfractiondigits.md)

### Constants

- [ByteCountFormatter.Units](foundation/bytecountformatter/units.md)
- [ByteCountFormatter.CountStyle](foundation/bytecountformatter/countstyle-swift.enum.md)

### Instance Methods

- [string(for:)](foundation/bytecountformatter/string(for:).md)
- [string(from:)](foundation/bytecountformatter/string(from:).md)

### Type Methods

- [string(from:countStyle:)](foundation/bytecountformatter/string(from:countstyle:).md)

## Relationships

### Inherits From

- [Formatter](foundation/formatter.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
