• 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: Trying to understand -- please help...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trying to understand -- please help...


  • Subject: Re: Trying to understand -- please help...
  • From: Andy Lee <email@hidden>
  • Date: Wed, 21 May 2008 15:41:17 -0400

On May 21, 2008, at 3:14 PM, Vijay Malhan wrote:
Thanks for the pointers to the documentation. This is sample snippet from
the documentation.


@implementation MyClass

+ (void)initialize

{

  if ( self == [MyClass class] ) {

      /* put initialization code here */

  }

}


If I'm not wrong "self" equivalent of "this" which points to an instance
var.

Not quite; "self" refers to the receiver of the +initialize message. Since +initialize is a class method, the receiver is a class.


Suppose you have a subclass of MyClass called MySubclass, and MySubclass doesn't implement its own version of +initialize. When MySubclass receives the +initialize message, it will run the inherited +initialize method. But then that method will get called twice: once for MySubclass and once for MyClass. The above code shows how to avoid this (if you want to avoid it).

This is explained in the paragraph preceding this code snippet, but I thought I'd try to spell it out a bit.

--Andy

_______________________________________________

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


References: 
 >Trying to understand -- please help... (From: Peter Hudson <email@hidden>)
 >Re: Trying to understand -- please help... (From: "I. Savant" <email@hidden>)
 >Re: Trying to understand -- please help... (From: "I. Savant" <email@hidden>)
 >Re: Trying to understand -- please help... (From: Vijay Malhan <email@hidden>)
 >Re: Trying to understand -- please help... (From: "Shawn Erickson" <email@hidden>)
 >Re: Trying to understand -- please help... (From: "Vijay Malhan" <email@hidden>)

  • Prev by Date: Trying to understand -- please help...
  • Next by Date: Re: Programmatically get treecontroller selection
  • Previous by thread: Re: Trying to understand -- please help...
  • Next by thread: Re: Trying to understand -- please help...
  • Index(es):
    • Date
    • Thread