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 (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 arch...@mail-archive.com

Reply via email to