Core Foundation is a library with a set of programming interfaces conceptually derived from the Foundation framework of the Cocoa object layer but implemented in the C language. To do this, Core Foundation implements a limited object model in C. Core Foundation defines opaque types that encapsulate data and functions, hereafter referred to as “objects.”
At a general level, Core Foundation
enables sharing of code and data among various frameworks and libraries
makes some degree of operating-system independence possible
supports internationalization with Unicode strings
provides common API and other useful capabilities, including a plug-in architecture, XML property lists, and preferences
It offers developers many fundamental software services on several platforms:
Mac OS 9 (when developing with the Carbon library)
Mac OS X (when developing with either Carbon or Cocoa)
As Figure 1 illustrates, Core Foundation on Mac OS 9 is a library that, when used together with Carbon, enables you to develop applications that can run on Mac OS 9, and Mac OS X.
Software Layers
Data Sharing
Operating-System Independence
Internationalization
On Mac OS X, you can think of Core Foundation as part of the substrata of system software called Core Services. This layer is immediately above the core operating system and below the services, frameworks and libraries used in application development. Figure 2 depicts these relationships.
Core Foundation makes it possible for the different frameworks and libraries on Mac OS X to share code and data. Carbon, Cocoa, and Mac OS 9 applications, libraries, and frameworks can define C routines that incorporate Core Foundation types in their external interfaces; they can thus communicate data—as Core Foundation objects—to each other through these interfaces. Indeed a Carbon developer could, for example, provide a Core Foundation-based service that can be used by any running application on a Mac OS X system regardless of its origin.
Core Foundation also provides “toll-free bridging” between certain services and the Cocoa’s Foundation framework. Toll-free bridging enables you to substitute Cocoa objects for Core Foundation objects in function parameters and vice versa.
Some Core Foundation types and functions are abstractions of things that have specific implementations on different operating systems. Code that makes use of these APIs is thus easier to port to different platforms.
Date and number types abstract time utilities and offers facilities for converting between absolute and Gregorian measures of time. It also abstracts numeric values and provides facilities for converting between different internal representations of those values.
Several other services that abstract operating-system utilities are available to Mac OS X native applications but not Carbon applications. Among these are inter-process notification and run-loop services.
One of the major benefits Core Foundation brings to application development is internationalization support. Through its String objects, Core Foundation facilitates easy, robust, and consistent internationalization across all Mac OS X and Cocoa programming interfaces and implementations. The essential part of this support is a type, CFString, instances of which represent an array of 16-bit Unicode characters. A CFString object is flexible enough to hold megabytes worth of characters and yet simple and low-level enough for use in all programming interfaces communicating character data. It accomplishes this with performance not much different than that associated with standard C strings.
Core Foundation String objects (which defines CFString) has dozens of associated functions that do expected things with strings such as comparing, inserting, and appending strings, and searching for substrings. String objects also provides functions that convert Unicode strings (that is, CFString objects) to and from other encodings, particularly 8-bit encodings stored as Pascal and C strings. Because most strings in programs today are 8-bit, a CFString object uses less memory for storing such strings whenever possible.
© 2003, 2005 Apple Computer, Inc. All Rights Reserved. (Last updated: 2005-08-11)