Re: Bundle loading
Re: Bundle loading
- Subject: Re: Bundle loading
- From: Marco Scheurer <email@hidden>
- Date: Fri, 23 Aug 2002 12:23:25 +0200
On Thursday, August 22, 2002, at 05:17 pm, Chris Ridd wrote:
On 22/8/02 1:41 pm, Marco Scheurer <email@hidden> wrote:
On Thursday, August 22, 2002, at 02:03 pm, Chris Ridd wrote:
Does loading a bundle in cause any code to get executed in the bundle
automatically, or any other kind of automatic initialization?
Basically if I write a bundle, how do I make sure that some kind of
initialization that I may require happens?
The docs are pretty unclear on this, as they seem to be mostly written
from
the point of view of the code loading the bundle in.
Look for + (void) load in NSObject, and be careful.
Ooh, interesting. What do I need to be wary of apart from the
caveats/warnings in the Foundation documentation?
I think that the safest thing to do would be for your application to
register for NSBundleDidLoadNotification and send an initialisation
message of your making to one class loaded from the bundle.
If that is not possible, for instance because you're writing a bundle
for a 3rd party application, I think you can assume that when a bundle
is loaded from a running application all Foundation, AppKit and the
application classes have been +loaded, so that using +load yourself can
be done safely.
If the code is loaded from a framework instead of a bundle, this could
not be the case.
A pattern I've seen and used for +load is to put all the initialisation
code in +initialize, and to implement +load like this:
+ (void) load
{
(void) [self class];
}
"Touching" the class like so will make sure that initialize is sent.
Does it provide complete protection against the caveat in the doc, by
making sure that everything is +loaded when our initialize is invoked? I
don't know, I haven't made experiments that would prove or disprove it,
but it worked in several cases in different environments (OPENSTEP,
WebObject 4, Cocoa) for code loaded from bundles as well as frameworks.
Marco Scheurer
Sen:te, Lausanne, Switzerland
http://www.sente.ch
_______________________________________________
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.