Re: mainbundle and frameworks
Re: mainbundle and frameworks
- Subject: Re: mainbundle and frameworks
- From: Bob Ippolito <email@hidden>
- Date: Sun, 29 May 2005 20:25:51 -0700
On May 29, 2005, at 8:15 PM, Mark Munz (DevList) wrote:
On May 29, 2005, at 6:53 PM, Bob Ippolito wrote:
On May 29, 2005, at 4:44 PM, Francisco Tolmasky wrote:
If I am writing a custom framework and I use [NSBundle
mainBundle], do I get the bundle that the framework is within, or
the bundle of the program using the framework? If I dont get the
bundle of the framework, then how can I access this bundle, or
inother words, a way to access the pathnames of resources within
the framework?
If you read the docs for +[NSBundle mainBundle], you should be
able to answer your own question.
As for finding the bundle of "where you're at", use [NSBundle
bundleForClass:[self class]] .. which is also mentioned in the
NSBundle documentation
I have read that bundleForClass is not as reliable as [NSBundle
bundleWithIdentifier:] and that bundleWithIdentifier is the better
choice.
The only time +bundleForClass: doesn't work is if the class was
generated at runtime. In those cases, since Mac OS X 10.4, the class
may implement +bundleForClass in order to specify that it should be
associated with some bundle other than the +mainBundle. PyObjC also
contains code that implements this feature on previous versions of
Mac OS X by swizzling the implementation if it doesn't do the right
thing already.
I would certainly choose +bundleForClass: over +bundleWithIdentifier:
in most code, because +bundleForClass: works wherever the class
happened to end up, so you don't need to refactor the identifier
constants if it moves to some other framework, directly to the
executable, etc.
-bob
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden