<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/DispatchData",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Dispatch"
    ],
    "preciseIdentifier" : "s:8Dispatch0A4DataV"
  },
  "title" : "DispatchData"
}
-->

# DispatchData

An object that manages a memory-based data buffer and exposes it as a contiguous block of memory.

```
struct DispatchData
```

## Overview

The memory buffer managed by this object may be a single contiguous block of memory, or it may consist of multiple discontiguous blocks. For the discontiguous case, the dispatch data object makes it appear as if the memory is contiguous.

## Topics

### Creating a Dispatch Data Structure

[`init(bytes:)`](/documentation/Dispatch/DispatchData/init(bytes:)-9lrd)

Creates a new dispatch data object from the specified memory buffer.

[`init(bytesNoCopy:deallocator:)`](/documentation/Dispatch/DispatchData/init(bytesNoCopy:deallocator:)-vfoe)

Creates a new dispatch data object using the specified memory buffer and deallocator.

[`withUnsafeBytes(body:)`](/documentation/Dispatch/DispatchData/withUnsafeBytes(body:))

[`DispatchData.Deallocator`](/documentation/Dispatch/DispatchData/Deallocator)

Memory deallocators for dispatch data objects.

[`empty`](/documentation/Dispatch/DispatchData/empty)

A dispatch data object representing a zero-length memory region.

### Appending Data to the Buffer

[`append(_:)`](/documentation/Dispatch/DispatchData/append(_:)-3bvdr)

[`append(_:)`](/documentation/Dispatch/DispatchData/append(_:)-9sgkq)

[`append(_:)`](/documentation/Dispatch/DispatchData/append(_:)-1m94x)

### Copying Bytes

[`copyBytes(to:count:)`](/documentation/Dispatch/DispatchData/copyBytes(to:count:)-3j0qx)

[`copyBytes(to:from:)`](/documentation/Dispatch/DispatchData/copyBytes(to:from:)-7zz4y)

[`copyBytes(to:from:)`](/documentation/Dispatch/DispatchData/copyBytes(to:from:)-60yai)

### Accessing Buffer Data

[`subscript(_:)`](/documentation/Dispatch/DispatchData/subscript(_:))

[`region(location:)`](/documentation/Dispatch/DispatchData/region(location:))

[`DispatchData.Region`](/documentation/Dispatch/DispatchData/Region)

### Getting Information About the Buffer

### Getting Buffer Indexes

### Offsetting Index Values

### Filtering the Buffer with a Predicate

### Iterating Over the Buffer Contents

[`makeIterator()`](/documentation/Dispatch/DispatchData/makeIterator())

[`enumerateBytes(_:)`](/documentation/Dispatch/DispatchData/enumerateBytes(_:))

### Retrieving Buffer Subsequences

[`subdata(in:)`](/documentation/Dispatch/DispatchData/subdata(in:))

### Comparing Buffer Data

### Mapping Buffer Elements

### Sorting Buffer Elements

### Getting the Publisher Object

### Combining Sequence Elements

[`append(_:)`](/documentation/Dispatch/DispatchData/append(_:)-3bvdr)

[`append(_:)`](/documentation/Dispatch/DispatchData/append(_:)-9sgkq)

[`append(_:)`](/documentation/Dispatch/DispatchData/append(_:)-1m94x)

[`append(_:count:)`](/documentation/Dispatch/DispatchData/append(_:count:))

[`copyBytes(to:count:)`](/documentation/Dispatch/DispatchData/copyBytes(to:count:)-4ffyj)

[`copyBytes(to:count:)`](/documentation/Dispatch/DispatchData/copyBytes(to:count:)-3j0qx)

[`copyBytes(to:from:)`](/documentation/Dispatch/DispatchData/copyBytes(to:from:)-7zz4y)

[`copyBytes(to:from:)`](/documentation/Dispatch/DispatchData/copyBytes(to:from:)-6ztcb)

[`copyBytes(to:from:)`](/documentation/Dispatch/DispatchData/copyBytes(to:from:)-60yai)

[`enumerateBytes(_:)`](/documentation/Dispatch/DispatchData/enumerateBytes(_:))

[`makeIterator()`](/documentation/Dispatch/DispatchData/makeIterator())

[`region(location:)`](/documentation/Dispatch/DispatchData/region(location:))

[`subdata(in:)`](/documentation/Dispatch/DispatchData/subdata(in:))

[`withUnsafeBytes(body:)`](/documentation/Dispatch/DispatchData/withUnsafeBytes(body:))

### Deprecated

[`init(bytes:)`](/documentation/Dispatch/DispatchData/init(bytes:)-mkbp)

Initialize a data object with copied memory content.

[`init(bytesNoCopy:deallocator:)`](/documentation/Dispatch/DispatchData/init(bytesNoCopy:deallocator:)-7h08w)

Initialize a data object without copying the bytes.

[`append(_:count:)`](/documentation/Dispatch/DispatchData/append(_:count:))

[`copyBytes(to:count:)`](/documentation/Dispatch/DispatchData/copyBytes(to:count:)-4ffyj)

[`copyBytes(to:from:)`](/documentation/Dispatch/DispatchData/copyBytes(to:from:)-6ztcb)



---

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)