bundleWithIdentifier:
Returns the previously created
NSBundle
instance that has the specified bundle identifier.
+ (NSBundle *)bundleWithIdentifier:(NSString *)identifier
Parameters
- identifier
- The identifier for an existing
NSBundle
instance.
Return Value of [NSBundle bundleWithIdentifier]
The previously created
NSBundle
instance that has the bundle identifier identifier. Returns nil
if the requested bundle is not found.Discussion of [NSBundle bundleWithIdentifier]
This method is typically used by frameworks and plug-ins to locate their own bundle at runtime. This method may be somewhat more efficient than trying to locate the bundle using the
bundleForClass:
method. However, if the initial lookup of an already loaded and cached bundle with the specified identifier fails, this method uses potentially time-consuming heuristics to attempt to locate the bundle.
Example of [NSBundle bundleWithIdentifier] - 1
NSString *bId = [props valueForKeyPath:@"IOMediaIcon.CFBundleIdentifier"];
NSString *rFile = [props valueForKeyPath:@"IOMediaIcon.IOBundleResourceFile"];
NSBundle *bundleWithIcon = [NSBundle bundleWithIdentifier:bId];
NSString *iconPath = [bundleWithIcon pathForResource:rFile ofType:nil];
Example of [NSBundle bundleWithIdentifier] - 2
NSBundle myBundle = [NSBundle bundleWithIdentifier:@"com.my.identifier"];
[myBundle pathForResource:@"myResource" ofType:@"type"];