<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 8.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/DataProtocol",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation12DataProtocolP"
  },
  "title" : "DataProtocol"
}
-->

# DataProtocol

A protocol that provides consistent data access to the bytes underlying contiguous and noncontiguous data buffers.

```
protocol DataProtocol : RandomAccessCollection where Self.Element == UInt8, Self.SubSequence : DataProtocol
```

## Topics

### Accessing Backing Storage

[`regions`](/documentation/Foundation/DataProtocol/regions-swift.property)

A collection of buffers that make up the whole of the type conforming to a data protocol.

[`Regions`](/documentation/Foundation/DataProtocol/Regions-swift.associatedtype)

A type that represents a collection of contiguous parts that make up the type conforming to a data protocol.

### Copying Underlying Bytes

[`copyBytes(to:)`](/documentation/Foundation/DataProtocol/copyBytes(to:)-52wps)

Copies the bytes of data from the type into a typed memory buffer.

[`copyBytes(to:)`](/documentation/Foundation/DataProtocol/copyBytes(to:)-3mk27)

Copies the bytes of data from the type into a raw memory buffer.

[`copyBytes(to:count:)`](/documentation/Foundation/DataProtocol/copyBytes(to:count:)-6krsm)

Copies the provided number of bytes from the start of the type into  a typed memory buffer.

[`copyBytes(to:count:)`](/documentation/Foundation/DataProtocol/copyBytes(to:count:)-29t5)

Copies the provided number of bytes from the start of the type into a raw memory buffer.

[`copyBytes(to:from:)`](/documentation/Foundation/DataProtocol/copyBytes(to:from:)-1ol47)

Copies a range of the bytes from the type into a typed memory buffer.

[`copyBytes(to:from:)`](/documentation/Foundation/DataProtocol/copyBytes(to:from:)-1y839)

Copies a range of the bytes from the type into a raw memory buffer.

### Searching Within Data

[`firstRange(of:)`](/documentation/Foundation/DataProtocol/firstRange(of:))

Returns the first found range of the type’s data buffer.

[`firstRange(of:in:)`](/documentation/Foundation/DataProtocol/firstRange(of:in:))

Returns the first found range of the type’s data buffer.

[`lastRange(of:)`](/documentation/Foundation/DataProtocol/lastRange(of:))

Returns the last found range of the type’s data buffer.

[`lastRange(of:in:)`](/documentation/Foundation/DataProtocol/lastRange(of:in:))

Returns the last found range of the type’s data buffer.



---

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)