Search Algorithm

When you ask CFBundle to locate a given resource, it performs a search to ensure that the right version of the resource is returned to you. Because resources can be global or localized as well as platform-specific, the search may be complex. CFBundle's resource-finding API insulates you from potential changes to the bundle packaging scheme and handles a lot of tricky searching issues so you. You should always use this API instead of groping around inside the bundle yourself.

The following list details the steps a CFBundle uses to locate a resource.

  1. Look for a global resource. If a global version of the resource is found, go to step 4, otherwise go to step 2.
  2. Look for a localized resource. The first place CFBundle searches, if present, is a folder containing resources localized for the region highest on the list specified by the user's Language/Region preference settings. If there is no set of resources localized for that specific region, but there are resources localized for that region's language, then those resources are searched. If this fails, then the search continues with the next region specified in the user's preference list. If a localized resource is found, go to step 4, otherwise go to step 3.
  3. If no localized resource was found for a region or language in the user's preferences and the bundle's development region (specified in the info plist) was not contained in the list, look in the bundle's development region resources. If the resource is found, go to step 4, otherwise give up and return NULL .
  4. Once a candidate resource is found, check to see if there is a platform-specific variant of the resource. If there is, return that resource's URL, otherwise return the generic resource's URL.

Notice that global resources take precedence over localized resources. In fact, there should never be both a global and localized version of a given resource. If there is a global version of a given resource, localized versions of that same resource will never be found. The reason for this precedence is performance. If the localizable resources were searched first, CFBundle might search needlessly in several localized resource folders before discovering the global resource. Also notice that in order to find a platform-specific resource, the platform-generic version must exist. Again, the reason is performance. You should generally make one platform's version of the resource be generic and provide platform-specific versions for any other platforms.

When it finds a resource, a CFBundle checks to see if a platform-specific version exists. Platform-specific resources are named using standard identifiers. The names you can use when making platform-specific resources are macosclassic (on Mac OS 8), macos (on Mac OS X). You construct the name of a platform-specific resource by combining the platform-generic name with the platform identifier string. For example, if you have a resource named Fish.jpg its Mac OS 8-specific name would be Fish-macosclassic.jpg . When an application running on Mac OS 8 requests the resource Fish.jpg , CFBundle also checks to see if Fish-macosclassic.jpg exists in that same folder. If it does, the CFBundle returns the path to the platform-specific resource; if it does not, it returns the path to Fish.jpg . As was mentioned previously, for Fish-macosclassic.jpg to be found, a file named Fish.jpg must exist in the same folder (including language-specific resource directories).


© 2000 Apple Computer, Inc. (Last Updated 30 June 2000)