< Previous PageNext Page > Hide TOC

Bundles and the Resource Manager

A bundle can contain any number of files with Resource Manager–style resources in their data forks. These resource files—which, by convention, have an extension of .rsrc —are treated as bundle resources just as any other kind of file under the Resources directory.

If your application requires specific resources at launch time, you can place those resources in one of two places and have Bundle Services load them for you automatically. For nonlocalized resources, place a file in your top-level Resources directory whose name is the same as the name of your executable but with a .rsrc extension. For localized resources, place a Localized.rsrc file in each of your language-specific directories.

For example, suppose your application is called MyApp and contains localizations for English, German, and Japanese. If you had both localized and nonlocalized resources you needed to load at launch time, your Resources directory would contain the following additional files:

MyApp.app/
    Contents/
        Resources/
            MyApp.rsrc
            English.lproj/
                Localized.rsrc
            German.lproj/
                Localized.rsrc
            Japanese.lproj/
                Localized.rsrc

The automatic loading of resources applies only to the listed files in your application bundle. If you load resources from frameworks or other loadable bundles, you must load those resources manually using the CFBundleOpenBundleResourceMap or CFBundleOpenBundleResourceFiles functions. These functions open the resource files and return reference numbers that you can pass to Resource Manager functions.

The following example shows you how to load an arbitrary resource from your bundle. The first step is to get a CFURL and then convert it to a FSRef. Once you have an FSRef, you can pass it to an appropriate Resource Manager call.

CFBundleRef myBundle;
CFURLRef tempURL;
FSRef myResource;
 
myBundle = CFBundleGetMainBundle();
tempURL = CFBundleCopyResourceURL (myBundle, CFSTR("MyResource"),
        CFSTR("rsrc"), NULL);
 
if (CFURLGetFSRef (tempURL, &myResource))
{
    // Open the resource using Resource Manager calls
}


< Previous PageNext Page > Hide TOC


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


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.