Getting Bundle by Path

suggest change
  1. Locating a Cocoa bundle using its path

To obtain the bundle at a specific path using Cocoa, call the bundleWithPath: class method of NSBundle.

NSBundle *myBundle;
// obtain a reference to a loadable bundle
myBundle = [NSBundle bundleWithPath:@"/Library/MyBundle.bundle"];
  1. Locating a Core Foundation bundle using its path

To obtain the bundle at a specific path using Core Foundation, call CFBundleCreate and pass a CFURLRef. The URL argument is bundleURL. CFBundleCreate returns a +1 object, so release it when you are done.

CFURLRef bundleURL;
CFBundleRef myBundle;
// Make a CFURLRef from the CFString representation of the bundle's path.
bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/Library/MyBundle.bundle"), kCFURLPOSIXPathStyle, true);
// Make a bundle instance using the URLRef.
myBundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);
// You can release the URL now.
CFRelease(bundleURL);
// Use the bundle ...
// Release the bundle when done.
CFRelease(myBundle);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents