---
title: "getBytes(_:range:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsdata/getbytes(_:range:)"
---

# getBytes(_:range:)

Copies a range of bytes from the data object into a given buffer.

## Declaration

```swift
func getBytes(_ buffer: UnsafeMutableRawPointer, range: NSRange)
```

## Parameters

- `buffer`: A buffer into which to copy data.
- `range`: The range of bytes in the receiver’s data to copy to buffer. The range must lie within the range of bytes of the receiver’s data.

## Discussion

Discussion If range isn’t within the receiver’s range of bytes, an rangeException is raised.

## See Also

### Related Documentation

- [description](foundation/nsdata/description.md)

### Accessing Underlying Bytes

- [bytes](foundation/nsdata/bytes.md)
- [enumerateBytes(_:)](foundation/nsdata/enumeratebytes(_:).md)
- [getBytes(_:)](foundation/nsdata/getbytes(_:).md)
- [getBytes(_:length:)](foundation/nsdata/getbytes(_:length:).md)
