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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to