<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSData/CompressionAlgorithm",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@E@NSDataCompressionAlgorithm"
  },
  "title" : "NSData.CompressionAlgorithm"
}
-->

# NSData.CompressionAlgorithm

An algorithm that indicates how to compress or decompress data.

```
enum CompressionAlgorithm
```

## Overview

Choose an algorithm that best suits the needs of your app:

- [`NSData.CompressionAlgorithm.lzfse`](/documentation/Foundation/NSData/CompressionAlgorithm/lzfse) — The algorithm offers faster speed and generally achieves better compression than   [`NSData.CompressionAlgorithm.zlib`](/documentation/Foundation/NSData/CompressionAlgorithm/zlib). However, it is slower than [`NSData.CompressionAlgorithm.lz4`](/documentation/Foundation/NSData/CompressionAlgorithm/lz4) and doesn’t compress as well as [`NSData.CompressionAlgorithm.lzma`](/documentation/Foundation/NSData/CompressionAlgorithm/lzma).
- [`NSData.CompressionAlgorithm.zlib`](/documentation/Foundation/NSData/CompressionAlgorithm/zlib) — Use this algorithm if your app requires interoperability with non-Apple devices. For example, if you are transferering data to another device where it needs to be compressed or decompressed.
- [`NSData.CompressionAlgorithm.lz4`](/documentation/Foundation/NSData/CompressionAlgorithm/lz4) — Use this algorithm if speed is critical, and you’re willing to sacrifice compression ratio to achieve it.
- [`NSData.CompressionAlgorithm.lzma`](/documentation/Foundation/NSData/CompressionAlgorithm/lzma) — Use this algorithm if compression ratio is critical, and you’re willing to sacrifice speed to achieve it. It is an order of magnitude slower for both compression and decompression than other choices.

## Topics

### Algorithms

[`NSDataCompressionAlgorithmLZ4`](/documentation/Foundation/NSData/CompressionAlgorithm/lz4)

The LZ4 compression algorithm, recommended for fast compression.

[`NSDataCompressionAlgorithmLZFSE`](/documentation/Foundation/NSData/CompressionAlgorithm/lzfse)

The LZFSE compression algorithm, recommended for use on Apple platforms.

[`NSDataCompressionAlgorithmLZMA`](/documentation/Foundation/NSData/CompressionAlgorithm/lzma)

The LZMA compression algorithm, recommended for high-compression ratio.

[`NSDataCompressionAlgorithmZlib`](/documentation/Foundation/NSData/CompressionAlgorithm/zlib)

The zlib compression algorithm, recommended for cross-platform compression.

## Relationships

### Conforms To

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

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

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

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

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

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

---

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)