---
title: "init(bytes:length:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsdata/init(bytes:length:)"
---

# init(bytes:length:)

Initializes a data object filled with a given number of bytes copied from a given buffer.

## Declaration

```swift
init(bytes: UnsafeRawPointer?, length: Int)
```

## Discussion

Discussion A data object initialized by adding to it length bytes of data copied from the buffer bytes. The returned object might be different than the original receiver.

## See Also

### Creating Data

- [init(bytesNoCopy:length:)](foundation/nsdata/init(bytesnocopy:length:).md)
- [init(bytesNoCopy:length:deallocator:)](foundation/nsdata/init(bytesnocopy:length:deallocator:).md)
- [init(bytesNoCopy:length:freeWhenDone:)](foundation/nsdata/init(bytesnocopy:length:freewhendone:).md)
- [init(data:)](foundation/nsdata/init(data:).md)
