<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFArray",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@T@CFArrayRef"
  },
  "title" : "CFArray"
}
-->

# CFArray

```
class CFArray
```

## Overview

CFArray and its derived mutable type, [`CFMutableArray`](/documentation/CoreFoundation/CFMutableArray), manage ordered collections of values called arrays. CFArray creates static arrays and CFMutableArray creates dynamic arrays.

You create a static array object using either the [`CFArrayCreate(_:_:_:_:)`](/documentation/CoreFoundation/CFArrayCreate(_:_:_:_:)) or [`CFArrayCreateCopy(_:_:)`](/documentation/CoreFoundation/CFArrayCreateCopy(_:_:)) function. These functions return an array containing the values you pass in as arguments. (Note that arrays can’t contain `NULL` pointers; in most cases, though, you can use the [`kCFNull`](/documentation/CoreFoundation/kCFNull) constant instead.) Values are not copied but retained using the retain callback provided when an array was created. Similarly, when a value is removed from an array, it is released using the release callback.

CFArray’s two primitive functions [`CFArrayGetCount(_:)`](/documentation/CoreFoundation/CFArrayGetCount(_:)) and [`CFArrayGetValueAtIndex(_:_:)`](/documentation/CoreFoundation/CFArrayGetValueAtIndex(_:_:)) provide the basis for all other functions in its interface. The [`CFArrayGetCount(_:)`](/documentation/CoreFoundation/CFArrayGetCount(_:)) function returns the number of elements in an array; [`CFArrayGetValueAtIndex(_:_:)`](/documentation/CoreFoundation/CFArrayGetValueAtIndex(_:_:)) gives you access to an array’s elements by index, with index values starting at 0.

A number of CFArray functions allow you to operate over a range of values in an array, for example [`CFArrayApplyFunction(_:_:_:_:)`](/documentation/CoreFoundation/CFArrayApplyFunction(_:_:_:_:)) lets you apply a function to values in an array, and [`CFArrayBSearchValues(_:_:_:_:_:)`](/documentation/CoreFoundation/CFArrayBSearchValues(_:_:_:_:_:)) searches an array for the value that matches its parameter. Recall that a range is defined as `{start, length}`, therefore to operate over the entire array the range you supply should be `{0, N}` (where `N` is the count of the array).

CFArray is “toll-free bridged” with its Cocoa Foundation counterpart, <doc://com.apple.documentation/documentation/Foundation/NSArray>. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. Therefore, in a method where you see an `NSArray *` parameter, you can pass in a `CFArrayRef`, and in a function where you see a `CFArrayRef` parameter, you can pass in an NSArray instance. This also applies to concrete subclasses of NSArray. See [Toll-Free Bridged Types](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/tollFreeBridgedTypes.html#//apple_ref/doc/uid/TP40010677) for more information on toll-free bridging.

## Topics

### Creating an Array

[`CFArrayCreate(_:_:_:_:)`](/documentation/CoreFoundation/CFArrayCreate(_:_:_:_:))

Creates a new immutable array with the given values.

[`CFArrayCreateCopy(_:_:)`](/documentation/CoreFoundation/CFArrayCreateCopy(_:_:))

Creates a new immutable array with the values from another array.

### Examining an Array

[`CFArrayBSearchValues(_:_:_:_:_:)`](/documentation/CoreFoundation/CFArrayBSearchValues(_:_:_:_:_:))

Searches an array for a value using a binary search algorithm.

[`CFArrayContainsValue(_:_:_:)`](/documentation/CoreFoundation/CFArrayContainsValue(_:_:_:))

Reports whether or not a value is in an array.

[`CFArrayGetCount(_:)`](/documentation/CoreFoundation/CFArrayGetCount(_:))

Returns the number of values currently in an array.

[`CFArrayGetCountOfValue(_:_:_:)`](/documentation/CoreFoundation/CFArrayGetCountOfValue(_:_:_:))

Counts the number of times a given value occurs in an array.

[`CFArrayGetFirstIndexOfValue(_:_:_:)`](/documentation/CoreFoundation/CFArrayGetFirstIndexOfValue(_:_:_:))

Searches an array forward for a value.

[`CFArrayGetLastIndexOfValue(_:_:_:)`](/documentation/CoreFoundation/CFArrayGetLastIndexOfValue(_:_:_:))

Searches an array backward for a value.

[`CFArrayGetValues(_:_:_:)`](/documentation/CoreFoundation/CFArrayGetValues(_:_:_:))

Fills a buffer with values from an array.

[`CFArrayGetValueAtIndex(_:_:)`](/documentation/CoreFoundation/CFArrayGetValueAtIndex(_:_:))

Retrieves a value at a given index.

### Applying a Function to Elements

[`CFArrayApplyFunction(_:_:_:_:)`](/documentation/CoreFoundation/CFArrayApplyFunction(_:_:_:_:))

Calls a function once for each element in range in an array.

### Getting the CFArray Type ID

[`CFArrayGetTypeID()`](/documentation/CoreFoundation/CFArrayGetTypeID())

Returns the type identifier for the CFArray opaque type.

### Callbacks

[`CFArrayApplierFunction`](/documentation/CoreFoundation/CFArrayApplierFunction)

Prototype of a callback function that may be applied to every value in an array.

[`CFArrayCopyDescriptionCallBack`](/documentation/CoreFoundation/CFArrayCopyDescriptionCallBack)

Prototype of a callback function used to get a description of a value in an array.

[`CFArrayEqualCallBack`](/documentation/CoreFoundation/CFArrayEqualCallBack)

Prototype of a callback function used to determine if two values in an array are equal.

[`CFArrayReleaseCallBack`](/documentation/CoreFoundation/CFArrayReleaseCallBack)

Prototype of a callback function used to release a value before it’s removed from an array.

[`CFArrayRetainCallBack`](/documentation/CoreFoundation/CFArrayRetainCallBack)

Prototype of a callback function used to retain a value being added to an array.

### Data Types

[`CFArrayCallBacks`](/documentation/CoreFoundation/CFArrayCallBacks)

Structure containing the callbacks of a CFArray.

### Constants

[Predefined Callback Structures](/documentation/CoreFoundation/predefined-callback-structures)

CFArray provides a predefined callback structure appropriate for use when the values in a CFArray are all CFType-derived objects.

## See Also

  [Property List Programming Topics for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFPropertyLists/CFPropertyLists.html#//apple_ref/doc/uid/10000130i)

  [Collections Programming Topics for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFCollections/CFCollections.html#//apple_ref/doc/uid/10000124i)



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)