Varieties of Objects

Opaque types come in up to three basic varieties, or “flavors,” based on the characteristics of editability and expandability expected in their objects:

Mutable objects are editable, meaning their contents can be changed. Immutable objects are not editable; once they are created they cannot be changed. Any attempt to change an immutable object usually results in an error of some kind. A fixed-size object has a maximum limit that it can grow to; in the case of a CFString, that would be the number of characters, and for a collection the limit would be the number of elements.

Some opaque types, such as CFString and CFArray, can create all three flavors of objects. Most opaque types can create immutable, fixed-size objects and typically have at least one unqualified creation function to do the job (such as CFArrayCreate). The determinant for mutable fixed-size versus variable-size is the value of the capacity or maximum-length parameter in the TypeCreateMutable function; any positive value results in a fixed-size object, but a 0 specifies a variable-size object.

References to mutable objects include “Mutable” in the type name, for example, CFMutableStringRef.