< Previous PageNext Page > Hide TOC

About Core Foundation

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

It offers developers many fundamental software services on several platforms:

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.


Figure 1  Core Foundation and Carbon on Mac OS 9

Core Foundation and Carbon on Mac OS 9

Contents:

Software Layers
Data Sharing
Operating-System Independence
Internationalization


Software Layers

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.


Figure 2  Core Foundation and other software layers on Mac OS X

Core Foundation and other software layers on Mac OS X

Data Sharing

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.

Operating-System Independence

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.

Internationalization

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.



< 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.