---
title: "withData(const OSData *, unsigned int, unsigned int)"
framework: kernel
role: pseudoSymbol
path: kernel/osdata/1808211-withdata
---

# withData(const OSData *, unsigned int, unsigned int)

Creates and initializes an instance of OSData with contents copied from a range within another OSData object.

## Declaration

```occ
static OSData * withData( 
 const OSData *inData, 
 unsigned intstart, 
 unsigned intnumBytes); 
```

## Parameters

- `inData`: An OSData object that provides the initial data.
- `start`: The starting index from which bytes will be copied.
- `numBytes`: The number of bytes to be copied from start.

## Return Value

Return Value An instance of OSData containing a copy of the specified data range from inData, with a reference count of 1; NULL on failure.

## Overview

Overview The new OSData object will grow as needed to accommodate more bytes (unlikeCFMutableData, for which a nonzero initial capacity is a hard limit).

## See Also

### Miscellaneous

- [appendByte](kernel/osdata/1808052-appendbyte.md)
- [appendBytes(const OSData *)](kernel/osdata/1808058-appendbytes.md)
- [appendBytes(const void *, unsigned int)](kernel/osdata/1808067-appendbytes.md)
- [ensureCapacity](kernel/osdata/1808072-ensurecapacity.md)
- [free](kernel/osdata/1808080-free.md)
- [getBytesNoCopy()](kernel/osdata/1808085-getbytesnocopy.md)
- [getBytesNoCopy(unsigned int, unsigned int)](kernel/osdata/1808094-getbytesnocopy.md)
- [getCapacity](kernel/osdata/1808100-getcapacity.md)
- [getCapacityIncrement](kernel/osdata/1808106-getcapacityincrement.md)
- [getLength](kernel/osdata/1808111-getlength.md)
- [initWithBytes](kernel/osdata/1808118-initwithbytes.md)
- [initWithBytesNoCopy](kernel/osdata/1808127-initwithbytesnocopy.md)
- [initWithCapacity](kernel/osdata/1808134-initwithcapacity.md)
- [initWithData(const OSData *)](kernel/osdata/1808141-initwithdata.md)
- [initWithData(const OSData *, unsigned int, unsigned int)](kernel/osdata/1808150-initwithdata.md)
- [isEqualTo(const OSData *)](kernel/osdata/1808160-isequalto.md)
- [isEqualTo(const OSMetaClassBase *)](kernel/osdata/1808165-isequalto.md)
- [isEqualTo(const OSString *)](kernel/osdata/1808172-isequalto.md)
- [isEqualTo(const void *, unsigned int)](kernel/osdata/1808178-isequalto.md)
- [serialize](kernel/osdata/1808185-serialize.md)
- [setCapacityIncrement](kernel/osdata/1808190-setcapacityincrement.md)
- [withBytes](kernel/osdata/1808195-withbytes.md)
- [withBytesNoCopy](kernel/osdata/1808197-withbytesnocopy.md)
- [withCapacity](kernel/osdata/1808204-withcapacity.md)
- [withData(const OSData *)](kernel/osdata/1808208-withdata.md)
