---
title: withArray
framework: kernel
role: pseudoSymbol
path: kernel/osarray/1808272-witharray
---

# withArray

Creates and initializes an OSArray populated with the contents of another array.

## Declaration

```occ
static OSArray * withArray( 
 const OSArray *array, 
 unsigned int capacity = 0); 
```

## Parameters

- `array`: An OSArray whose contents will be stored in the new instance.
- `capacity`: The initial storage capacity of the array object. If 0, the capacity is set to the number of objects in array; otherwise capacity must be greater than or equal to the number of objects in array.

## Return Value

Return Value An instance of OSArray containing the objects of array, with a retain count of 1; NULL on failure.

## Overview

Overview array must be non-NULL. If capacity is nonzero, it must be greater than or equal to count. The new array will grow as needed to accommodate more objects (unlikeCFMutableArray, for which the initial capacity is a hard limit). The objects in array are retained for storage in the new OSArray, not copied.

## See Also

### Miscellaneous

- [copyCollection](kernel/osarray/1808122-copycollection.md)
- [ensureCapacity](kernel/osarray/1808132-ensurecapacity.md)
- [flushCollection](kernel/osarray/1808145-flushcollection.md)
- [free](kernel/osarray/1808156-free.md)
- [getCapacity](kernel/osarray/1808168-getcapacity.md)
- [getCapacityIncrement](kernel/osarray/1808174-getcapacityincrement.md)
- [getCount](kernel/osarray/1808184-getcount.md)
- [getLastObject](kernel/osarray/1808193-getlastobject.md)
- [getNextIndexOfObject](kernel/osarray/1808202-getnextindexofobject.md)
- [getObject](kernel/osarray/1808210-getobject.md)
- [initWithArray](kernel/osarray/1808216-initwitharray.md)
- [initWithCapacity](kernel/osarray/1808222-initwithcapacity.md)
- [initWithObjects](kernel/osarray/1808226-initwithobjects.md)
- [isEqualTo(const OSArray *)](kernel/osarray/1808231-isequalto.md)
- [isEqualTo(const OSMetaClassBase *)](kernel/osarray/1808236-isequalto.md)
- [merge](kernel/osarray/1808242-merge.md)
- [removeObject](kernel/osarray/1808246-removeobject.md)
- [replaceObject](kernel/osarray/1808249-replaceobject.md)
- [serialize](kernel/osarray/1808255-serialize.md)
- [setCapacityIncrement](kernel/osarray/1808259-setcapacityincrement.md)
- [setObject(const OSMetaClassBase *)](kernel/osarray/1808261-setobject.md)
- [setObject(unsigned int, const OSMetaClassBase *)](kernel/osarray/1808266-setobject.md)
- [withCapacity](kernel/osarray/1808279-withcapacity.md)
- [withObjects](kernel/osarray/1808285-withobjects.md)
