< Previous PageNext Page > Hide TOC

Searching for Bundle Resources

As long as you use the CFBundle and NSBundle programming interfaces, your bundle code need never concern itself with how resources are retrieved from a bundle. Both CFBundle and NSBundle automatically retrieve the appropriate language-specific resource based on the available user settings and bundle information. However, you still have to put all those language-specific resources into your bundle, so knowing how they are retrieved is important.

The bundle programming interfaces follow a specific search algorithm to locate resources within the bundle. Global resources have the highest priority, followed by region- and language-specific resources. When considering region- and language-specific resources, the algorithm takes into account both the settings for the current user and development region information in the bundle’s Info.plist file. The bundle interfaces use a case-sensitive search to locate the appropriate resource files. The following list shows the order in which resources are searched:

  1. Global resources

  2. Region-specific resources (based on the user’s region preferences)

  3. Language-specific resources (based on the user’s language preferences)

  4. Development language of the bundle (as specified by the CFBundleDevelopmentRegionKey in the bundle’s Info.plist file.)

If a resource is found, the bundle interfaces then check to see if there is a platform-specific version that should be returned instead. If one is available, it is returned; otherwise, the original platform-generic resource is returned.

Note: See “Adding Localized Resources” for an example that shows where to put global and language-specific resources reside within a bundle.

Because global resources take precedence over language-specific resources, there should never be both a global and localized version of a given resource. If a global version of a resource exists, language-specific versions of the same resource are never returned. The reason for this precedence is performance. If localized resources were searched first, the bundle routines might search needlessly in several localized resource directories before discovering the global resource.

Also notice that if your bundle includes any platform-specific resources, you must also include a complete set of platform-generic resources as well. Again, the reason is performance. You would typically create a generic resource that applies to most platforms and then offer customized versions only if it was relevant. See “Adding Platform-Specific Resources” for information and examples of how to create platform-specific resources.



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