The problem of managing code and related resources is not a new one and different operating systems have taken different approaches. In the past, resources have been compiled into the executable file, compiled into resource forks, and installed in known locations, among other techniques. The problem with many of these techniques is that they tend to be more fragile and in some cases complicate the process of updating the code and resources.
Bundles provide an elegant solution to the problem of grouping related code and resources together. A bundle is a hierarchical directory structure containing executable code and resources geared for a specific purpose. Applications, frameworks, and plug-ins can all be implemented as bundles in Mac OS X, and in fact, bundles are the preferred delivery mechanism for all of these software types. Developers can also use bundles for other purposes, including the implementation of custom document types.
Important: It is important to remember the distinction between what is a bundle and what is a package. The term bundle indicates a directory with a specific hierarchical structure, whereas the term package indicates a directory that is treated as an opaque entity by the Finder. Most bundles (including applications and plug-ins) are also packages. Some bundles, such as frameworks, are not packages, however.
Advantages of Using Bundles
Types of Bundles
Programmatic Support for Bundles
Bundles provide significant advantages over other application packaging schemes available on Mac OS X.
Bundles are directory hierarchies in the file system. A bundle contains real files that can be manipulated by all file-based services and API.
The bundle directory structure makes it easy to support multiple localizations. You can easily add new localized resources or remove unwanted ones.
Bundles can reside on volumes of many different formats, including multiple fork formats like HFS, HFS+, and AFP, and single-fork formats like UFS, SMB, and NFS.
Users can install, relocate, and remove bundles simply by dragging them around in the Finder.
Bundles that are also packages, and are therefore treated as opaque files, are less susceptible to accidental user modifications, such as removal, modification, or renaming of critical resources.
A bundle can include separate executables for different target platforms. For example, a bundled application could include separate executables for Mac OS 9 and Mac OS X.
A bundle can support multiple chip architectures (PowerPC, Intel), library architectures (CFM/MachO), and other special executables (for example, optimized libraries for AltiVec).
Most executable code can be bundled. Applications, frameworks (shared libraries), and plug-ins all support the bundle model.
An application can run directly from a server. No special shared libraries, extensions, and resources need to be installed on the local system.
The type of a bundle determines its internal directory structure and the location of key resources within that structure. Mac OS X supports two basic bundle types: modern and versioned. The modern bundle type is the one most commonly found on the system and is used to implement applications, plug-ins, and most other executables. The versioned bundle type is used almost exclusively to implement frameworks and umbrella frameworks.
For information about the structure of a modern bundle, see “Anatomy of a Modern Bundle.” For information about the structure of versioned bundles, see “Anatomy of Framework Bundles” in Framework Programming Guide.
Programs that refer to bundles, or are themselves bundled, can take advantage of interfaces in Core Foundation and Cocoa to access the contents of a bundle. Using these interfaces you can find bundle resources, get information about the bundle’s configuration, and load executable code. Cocoa programs use an NSBundle
object to manage bundle information. Most other programs use the CFBundle
object and C-based functions that are part of Core Foundation.
Note: Unlike many other Core Foundation and Cocoa types, CFBundle
and NSBundle
are not toll-free bridged data types and cannot be used interchangeably. However, you can extract the bundle path information from either object and use it to create the other.
© 2003, 2005 Apple Computer, Inc. All Rights Reserved. (Last updated: 2005-11-09)