---
title: withObjects
framework: Kernel
role: symbol
role_heading: Type Method
platforms: [driverkit 19.0+, macOS 10.15+]
path: kernel/osarray/3180825-withobjects
---

# withObjects

Allocates an OSArray object with given members and preallocated capacity.

## Declaration

```occ
static OSArrayPtr withObjects(const OSObject **values, uint32_t count, uint32_t capacity);
```

```occ
static OSPtr<OSArray> withObjects(const OSObject *objects[], unsigned int count, unsigned int capacity);
```

## Parameters

- `values`: C-array pointer to members for the array.
- `count`: Count of members being added to the array.
- `capacity`: Count of allocated capacity for members in array.

## Return Value

Return Value NULL on failure, otherwise the allocated OSArray with reference count 1 to be released by the caller.

## See Also

### Creating an Array

- [withArray](kernel/osarray/3180823-witharray.md)
- [withCapacity](kernel/osarray/3180824-withcapacity.md)
- [merge](kernel/osarray/3180819-merge.md)
- [free](kernel/osarray/3180811-free.md)
- [flushCollection](kernel/osarray/3180810-flushcollection.md)
