< Previous PageNext Page > Hide TOC

Object References

You refer to Core Foundation objects (opaque types) through references. In every header file for an opaque type, you will notice a line or two similar to the following:

typedef const struct __CFArray * CFArrayRef;
typedef struct __CFArray * CFMutableArrayRef;

Declarations such as these are pointer references to immutable and mutable versions of the (private) structure defining the opaque type. The parameters and return values of many Core Foundation functions take the type of these object references and never a typedef of the private structure. For example:

CFStringRef CFStringCreateByCombiningStrings(CFAllocatorRef alloc, CFArrayRef array, CFStringRef separatorString);

See “Varieties of Objects” for more on immutable, mutable, and other variants of opaque-type objects.

Every Core Foundation opaque type defines a unique type ID for its objects, as in CFArrayRef above for CFArray objects. A type ID is an integer of type CFTypeID that identifies the opaque type to which a Core Foundation object “belongs.” You use type IDs in various contexts, such as when you are operating on heterogeneous collections. Core Foundation provides programmatic interfaces for obtaining and evaluating type IDs.

Important: Because the value for a type ID can change from release to release, your code should not rely on stored or hard-coded type IDs nor should it hard-code any observed properties of a type ID (such as, for example, it being a small integer).

In addition, Core Foundation defines a generic object-reference type, CFTypeRef, analogous to a root class in some object-oriented programming languages. This generic reference serves as a placeholder type for parameters and returned values of polymorphic functions, which can take references to any Core Foundation object. See “Polymorphic Functions” for more on this subject. See “Memory Management” for issues relating to memory management when using object references.



< Previous PageNext Page > Hide TOC


© 2003, 2005 Apple Computer, Inc. All Rights Reserved. (Last updated: 2005-08-11)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.