---
title: "enumerateBytes(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/data/enumeratebytes(_:)"
---

# enumerateBytes(_:)

Enumerates the contents of the data’s buffer.

## Declaration

```swift
func enumerateBytes(_ block: (UnsafeBufferPointer<UInt8>, Data.Index, inout Bool) -> Void)
```

## Parameters

- `block`: The closure to invoke for each region of data. You may stop the enumeration by setting the stop parameter to true.

## Discussion

Discussion In some cases, (for example, a Data backed by a dispatch_data_t, the bytes may be stored discontiguously. In those cases, this function invokes the closure for each contiguous region of bytes.

## See Also

### Iterating Over Bytes

- [makeIterator()](foundation/data/makeiterator().md)
- [Data.Iterator](foundation/data/iterator.md)
