On Tue, Nov 10, 2009 at 6:57 AM, Kiel Gillard <kiel.gill...@gmail.com> wrote:
> On 10/11/2009, at 10:51 PM, Benjamin Miller wrote:
>
>> On 10 Nov 2009, at 11:45, Motti Shneor wrote:
>>
>>> This may seem a silly question, but I cannot find any decent way for my
>>> Plug-In bundle code to access its own resources!
>>>
>>> ... snip ...
>>>
>>> Is there a way out? Is there any trick, or technique to work around this
>>> bizarre deficiency of the Bundle mechanism?
>>
>>
>>
>> [[NSBundle bundleForClass] self class] ?
>
> More correctly:
>
> NSBundle *pluginBundle = [NSBundle bundleForClass:[self class]];
> <http://developer.apple.com/mac/library/documentation/cocoa/reference/foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/occ/clm/NSBundle/bundleForClass:>
>
> Then you can access the paths of the resources associated with that bundle
> using the usual methods identified in the reference given above.

It's best to avoid [self class] for things like this, because your
class can be subclassed, causing bundleForClass: to give you the wrong
answer. You might even get the wrong answer if the subclass is one of
those fun dynamically-created subclasses that you get when using KVO.

To get the bundle that you're writing code for, either provide an
explicit class ([NSBundle bundleForClass:[MyFoo class]]) or use
bundleWithIdentifier:.

Mike
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to