Re: Trying to understand -- please help...
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