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.
NULL
.In order to help you visualize the algorithm, Figure 1 pictures the search process in flow chart form.
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
macos8
(on Mac OS 8),
macosx
(on Mac OS X),
windows
(on OPENSTEP for Windows),
hpux
(on PDO for HP-UX), and
solaris
(on PDO for Solaris). 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-macos8.jpg
. When an application running on Mac OS 8 requests the resource
Fish.jpg
, CFBundle also checks to see if
Fish-macos8.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-macos8.jpg
to be found, a file named
Fish.jpg
must exist in the same folder (including language-specific resource directories).