<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSData/enumerateBytes(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSData(im)enumerateByteRangesUsingBlock:"
  },
  "title" : "enumerateBytes(_:)"
}
-->

# enumerateBytes(_:)

Enumerates each range of bytes in the data object using a block.

```
func enumerateBytes(_ block: (UnsafeRawPointer, NSRange, UnsafeMutablePointer<ObjCBool>) -> Void)
```

## Parameters

`block`

The block to apply to byte ranges in the array.

    The block takes three arguments:

- bytes: The bytes for the current range. This pointer is valid until the data object is deallocated.
- byteRange: The range of the current data bytes.
- stop: A reference to a Boolean value. The block can set the value to <doc://com.apple.documentation/documentation/Swift/true> to stop further processing of the data. The stop argument is an out-only argument. You should only ever set this Boolean to <doc://com.apple.documentation/documentation/Swift/true> within the Block.

## Discussion

The enumeration block is called once for each contiguous region of memory in the receiver (once total for a contiguous [NSData](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/PropertyLists/OldStylePlists/OldStylePLists.html#//apple_ref/doc/uid/20001012-47169) object), until either all bytes have been enumerated, or the `stop` parameter is set to <doc://com.apple.documentation/documentation/Swift/true>.

---

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)