Re: Forcing allocation of a subclass
Re: Forcing allocation of a subclass
- Subject: Re: Forcing allocation of a subclass
- From: Jean-Daniel Dupas <email@hidden>
- Date: Sun, 25 Jan 2009 16:21:08 +0100
Le 25 janv. 09 à 15:31, João Varela a écrit :
Hi Jean-Daniel
Yes, when I re-read what I wrote I know it can cause confusion. Of
course 'self' is a pointer to a class instance, not to a class, but
I didn't know that 'self' was itself a method.
No, self is not a method, it's a parameter.
Obj-C methods have two hidden parameters (at least with the Apple
runtime) : id self, SEL _cmd.
In a class method, they are equivalent to : Class self, SEL _cmd.
Can you point me to the documentation where that is written? Of
course "+ [NSObject class]" returns a class, not a class name (my
bad). I said what I said based on listing 2-7 of the page I
mentioned, but I now realize there is a slight difference with what
Antonio has posted.
So you mean that
if ( self == [aReceiver class] )
is the same as
if ( [self class] == [aReceiver class] ) ?
Yes it is.
Just a simple snippet to try to help you to understand.
We are ok to say that in a method, self represents the receiver.
Now have a look at this call:
[PDFDocument allocWithZone:nil]
You are ok to say that it is equivalents to:
[[PDFDocument class] allocWithZone:nil]
With the second form, you clearly see here that the receiver is
[PDFDocument class]. And as self is the receiver, (self ==
[PDFDocument class]) is perfectly valid to test class equality.
_______________________________________________
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