---
title: "dataWithBytes:length:"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsdata/datawithbytes:length:"
---

# dataWithBytes:length:

Creates a data object containing a given number of bytes copied from a given buffer.

## Declaration

```occ
+ (instancetype) dataWithBytes:(const void *) bytes length:(NSUInteger) length;
```

## Parameters

- `bytes`: A buffer containing data for the new object.
- `length`: The number of bytes to copy from bytes. This value must not exceed the length of bytes.

## See Also

### Creating Data

- [data](foundation/nsdata/data.md)
- [dataWithBytesNoCopy:length:](foundation/nsdata/datawithbytesnocopy:length:.md)
- [dataWithBytesNoCopy:length:freeWhenDone:](foundation/nsdata/datawithbytesnocopy:length:freewhendone:.md)
- [dataWithData:](foundation/nsdata/datawithdata:.md)
- [init(bytes:length:)](foundation/nsdata/init(bytes:length:).md)
- [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)
