• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Bundles work differently depending on application launch path?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bundles work differently depending on application launch path?


  • Subject: Bundles work differently depending on application launch path?
  • From: Stuart Halloway <email@hidden>
  • Date: Fri, 16 Jan 2004 09:07:39 -0500

[NSBundle mainBundle] works to load classes from the mainBundle if you launch a console application from the current directory. However, if you launch from some other directory, specifying a relative path to the application, you can no longer use [NSBundle mainBundle] to load classes.

The output from the method below is instructive. [NSBundle mainBundle] and [NSBundle bundleForClass:[self class]] return the same object if you launch from the application directory, but different objects if you launch using a relative path.

Any ideas for a workaround to get mainBundle working again?

Stu


- (void) testBundles {
NSArray* bundles = [NSBundle allBundles];
NSEnumerator* en = [bundles objectEnumerator];
NSBundle* bundle;
while (bundle= [en nextObject]) {
NSLog(@"Bundle %X has path %@ xpath %@", (long) bundle, [bundle bundlePath], [bundle executablePath]);
}
bundle = [NSBundle mainBundle];
NSLog(@"Main Bundle %X has path %@ xpath %@", (long) bundle, [bundle bundlePath], [bundle executablePath]);

bundle = [NSBundle bundleForClass:[NSObject class]];
NSLog(@"NSObject Bundle %X has path %@ xpath %@", (long) bundle, [bundle bundlePath], [bundle executablePath]);

bundle = [NSBundle bundleForClass:[self class]];
NSLog(@"Self Bundle %X has path %@ xpath %@", (long) bundle, [bundle bundlePath], [bundle executablePath]);
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Follow-Ups:
    • Re: Bundles work differently depending on application launch path?
      • From: Douglas Davidson <email@hidden>
  • Prev by Date: Weird screen saver problem when passwort required to undim screen
  • Next by Date: Re: Autorelease pool question
  • Previous by thread: Weird screen saver problem when passwort required to undim screen
  • Next by thread: Re: Bundles work differently depending on application launch path?
  • Index(es):
    • Date
    • Thread