Re: Trying to understand -- please help...
Re: Trying to understand -- please help...
- Subject: Re: Trying to understand -- please help...
- From: "Sherm Pendley" <email@hidden>
- Date: Wed, 21 May 2008 16:52:17 -0400
On Wed, May 21, 2008 at 3: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.
In a class method, self points to the class object, not to an instance.
> And it is initialized in - init (instance)method.
That makes no sense at all. +initialize a class method, not an instance
method, and it's guaranteed to be called before any other method.
> initialize, it's nil. So does "self" even exist when + initialize is
> called.
> Cuz as per documentation it is the first method called for a Class, before
> +alloc and -init methods are called.
>
> Or the comparison condition in above example is not valid.
The above comparison simply checks "self" against a specific Class object,
so that this +initialize won't have any effect in subclasses.
Once again - you seriously need to take a step back and review the
fundamentals docs. It's a dead-end to try to learn by skipping the
fundamentals, going straight to the references and thinking in terms of
equivalent constructs in Java, C++, or whatever. You need to approach and
learn Cocoa on its own terms.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
_______________________________________________
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