CFArray and its derived mutable type, 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 or 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 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 and CFArrayGetValueAtIndex provide the basis for all other functions in its interface. The CFArrayGetCount function returns the number of elements in an array; 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 lets you apply a function to values in an array, and 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, 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 for more information on toll-free bridging.


Creating an Array


Creates a new immutable array with the given values.


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

Examining an Array


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


Reports whether or not a value is in an array.


Returns the number of values currently in an array.


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


Searches an array forward for a value.


Searches an array backward for a value.


Fills a buffer with values from an array.


Retrieves a value at a given index.

Applying a Function to Elements


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

Getting the CFArray Type ID


Returns the type identifier for the CFArray opaque type.



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


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


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


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


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

Data Types


Structure containing the callbacks of a CFArray.


A reference to an immutable array object.


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

Opaque Types


The CFFileDescriptor provides an opaque type to monitor file descriptors for read and write activity via CFRunLoop.


CFStringTokenizer allows you to tokenize strings into words, sentences or paragraphs in a language-neutral way. It supports languages such as Japanese and Chinese that do not delimit words by spaces, as well as de-compounding German compounds. You can obtain Latin transcription for tokens. It also provides language identification API.