Re: Double Initialize - is that how it should be?
Re: Double Initialize - is that how it should be?
- Subject: Re: Double Initialize - is that how it should be?
- From: Dave Keck <email@hidden>
- Date: Mon, 16 Mar 2009 16:40:01 -1000
This is expected behavior; from the docs:
The runtime sends initialize to each class in a program exactly one
time just before the class, or any class that inherits from it, is
sent its first message from within the program. (Thus the method may
never be invoked if the class is not used.) The runtime sends the
initialize message to classes in a thread-safe manner. Superclasses
receive this message before their subclasses.
...
If a particular class does not implement initialize, the initialize
method of its superclass is invoked twice, once for the superclass and
once for the non-implementing subclass. If you want to make sure that
your class performs class-specific initializations only once,
implement initialize as in the following example:
@implementation MyClass
+ (void)initialize
{
if ( self == [MyClass class] ) {
/* put initialization code here */
}
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden