Re: + initialize docs conflict?
Re: + initialize docs conflict?
- Subject: Re: + initialize docs conflict?
- From: Ricky Sharp <email@hidden>
- Date: Tue, 01 Feb 2005 13:43:34 -0600
On Tuesday, February 01, 2005, at 01:37PM, mmalcolm crawford <email@hidden> wrote:
>
>On Feb 1, 2005, at 6:59 AM, Buck, Erik (Space Technology) wrote:
>
>> I believe the issue with a single +initialize implementation being
>> called multiple times is the following:
>> The run-time sends the +initialize message to each class once.
>> However, if the class does not implement the +initialize method, an
>> inherited implementation is called.
>> For example, NSControl is a subclass of NSView.
>> The runtime sends the +initialize message to NSView.
>> Then the runtime sends the +initialize message to NSControl.
>
>To be candid I don't remember what the exact sequence is, but this
>seems to fit with the standard "solution" I have always encountered:
>
>@implementation MyClass
>
>+ initialize
>{
> if (self == [MyClass class])
> {
> // initialize MyClass
> }
>}
>
>// ...
>
>
>This avoids the need to use the one shot static...
I've seen (and have been using) this pattern in NSControl subclasses that need to set their associate cell. For example,
+ (void)initialize
{
if (self == [IIButton class])
{
[self setCellClass:[IIButtonCell class]];
}
}
--
Rick Sharp
Instant Interactive(tm)
_______________________________________________
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