<!--
{
  "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/format(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation11MeasurementVAASo11NSDimensionCRbzrlE11FormatStyleVAASo24NSUnitInformationStorageCRszrlE9ByteCountV6formatySSACyAIGF"
  },
  "title" : "format(_:)"
}
-->

# format(_:)

Formats a byte count measurment, using this style.

```
func format(_ value: Measurement<UnitInformationStorage>) -> String
```

## Parameters

`value`

The byte count measurement to format.

## Return Value

A formatted representation of `value`, formatted according to the style’s configuration.

## Discussion

Use this method when you want to create a single style instance, and then use it to format multiple values. The following example creates a [`Measurement.FormatStyle.ByteCount`](/documentation/Foundation/Measurement/FormatStyle/ByteCount) instance to format values as kilobyte counts, then applies this style to an array of [`Measurement`](/documentation/Foundation/Measurement) values.

```swift
let style = Measurement.FormatStyle.ByteCount(style: .memory,                                              
                                              allowedUnits: [.kb],
                                              spellsOutZero: true,
                                              includesActualByteCount: false,
                                              locale: Locale(identifier: "en_US"))
let counts: [Measurement] = [
    Measurement(value: 0, unit: UnitInformationStorage.bytes),
    Measurement(value: 1024, unit: UnitInformationStorage.bytes),
    Measurement(value: 2048, unit: UnitInformationStorage.bytes),
    Measurement(value: 4096, unit: UnitInformationStorage.bytes),
    Measurement(value: 8192, unit: UnitInformationStorage.bytes),
    Measurement(value: 16384, unit: UnitInformationStorage.bytes),
    Measurement(value: 32768, unit: UnitInformationStorage.bytes),
    Measurement(value: 65536, unit: UnitInformationStorage.bytes)
]
let formatted = counts.map ( {style.format($0) } ) // ["Zero kB", "1 kB", "2 kB", "4 kB", "8 kB", "16 kB", "32 kB", "64 kB"]
```

To format a single data-storage measurement, use the Measurement instance method [`formatted(_:)`](/documentation/Foundation/Measurement/formatted(_:)), passing in an instance of [`Measurement.FormatStyle.ByteCount`](/documentation/Foundation/Measurement/FormatStyle/ByteCount), or [`formatted()`](/documentation/Foundation/Measurement/formatted()) to use a default style.

---

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)