Re: mainbundle and frameworks
Re: mainbundle and frameworks
- Subject: Re: mainbundle and frameworks
- From: Douglas Davidson <email@hidden>
- Date: Mon, 30 May 2005 10:29:36 -0700
On May 29, 2005, at 8:25 PM, Bob Ippolito wrote: 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.
You are right on the mark, except that I would add that you should choose whichever of these best expresses your actual intentions. There are cases in which what you really want is the bundle containing a particular class (for example, [self class]), and in those cases bundleForClass: would be a good choice. There are other cases, however, in which you are looking for resources that are associated more with a particular framework than with any individual class, and for those cases it would probably be better to use bundleWithIdentifier: rather than to pick some arbitrary class in that framework to use with bundleForClass:.
Douglas Davidson
|
_______________________________________________
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