Re: Trying to understand -- please help...
Re: Trying to understand -- please help...
- Subject: Re: Trying to understand -- please help...
- From: "Shawn Erickson" <email@hidden>
- Date: Wed, 21 May 2008 12:24:48 -0700
On Wed, May 21, 2008 at 12:14 PM, Vijay Malhan <email@hidden> 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.
self (and this in C++) do not point to an instance var, to are an
implicit / hidden parameter to methods that give you a reference to
the object your method is operating "under the context of".
> And it is initialized in - init (instance)method.
Nope. Again self is an implicit method parameter.
> And if it fails to initialize, it's nil.
If you are in a class or instance method self is valid (otherwise you
wouldn't be in the method) and it will remain valid unless you do
something to invalidate it (set self to something else or otherwise
cause the object self is referencing to be deallocated, etc.).
> So does "self" even exist when + initialize is called.
In the case of class methods in objective-c (those with + in front)
self is a reference the class object.
<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_2_section_4.html#//apple_ref/doc/uid/TP30001163-CH11-TPXREF115>
<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_8_section_5.html>
-Shawn
_______________________________________________
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