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

# getBytes(_:length:)

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

## Declaration

```swift
func getBytes(_ buffer: UnsafeMutableRawPointer, length: Int)
```

## Parameters

- `buffer`: A buffer into which to copy data.
- `length`: The number of bytes from the start of the receiver’s data to copy to buffer.

## Discussion

Discussion The number of bytes copied is the smaller of the length parameter and the length of the data encapsulated in the object.

## 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(_:range:)](foundation/nsdata/getbytes(_:range:).md)
