pathsForResourcesOfType :inDirectory:
Returns an array containing the pathnames for all bundle resources having the specified extension and residing in the bundle directory at the specified path.
Parameters
- extension
- The file extension. If extension is an empty string or
nil
, the extension is assumed not to exist, all the files in bundlePath are returned. - bundlePath
- The top-level directory of a bundle. This must represent a valid path.
Return Value of [NSBundle pathsForResourcesOfType]
An array containing the full pathnames for all bundle resources with the specified extension. This method returns an empty array if no matching resource files are found. It also returns an empty array if the bundle specified by the
bundlePath
parameter does not exist or is not a readable directory.Discussion of [NSBundle pathsForResourcesOfType]
This method provides a means for dynamically discovering multiple bundle resources of the same type.
The method first looks for matching resource files in the nonlocalized resource directory of the specified bundle. (In OS X, this directory is typically called
Resources
but in iOS, it is the main bundle directory.)[NSBundle pathsForResourcesOfType] It then looks in the top level of any available language-specific “.lproj
” directories. It does not recurse through other subdirectories at any of these locations. For more details see Internationalization Programming Topics.
Example of [NSBundle pathsForResourcesOfType]
// Load item icons
paths = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:nil];
for (NSString *filename in paths) {
filename = [[filename componentsSeparatedByString:@"/"] lastObject];
if ([filename hasPrefix:@"ItemIcon"]) {
[UIImage imageNamed:filename];
}
}