• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: + initialize docs conflict?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: + initialize docs conflict?
      • From: Shaun Wexler <email@hidden>
References: 
 >Re: + initialize docs conflict? (From: "Buck, Erik (Space Technology)" <email@hidden>)
 >Re: + initialize docs conflict? (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: catching mouseDown in NSTableView
  • Next by Date: Re: + initialize docs conflict?
  • Previous by thread: Re: + initialize docs conflict?
  • Next by thread: Re: + initialize docs conflict?
  • Index(es):
    • Date
    • Thread