Re: Forcing allocation of a subclass
Re: Forcing allocation of a subclass
- Subject: Re: Forcing allocation of a subclass
- From: Michael Ash <email@hidden>
- Date: Sun, 25 Jan 2009 10:23:31 -0500
On Sun, Jan 25, 2009 at 9:31 AM, João Varela <email@hidden> wrote:
> 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. 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] ) ?
>
> If it is, sorry for the noise, but I would find it weird that a pointer to a
> class instance also had the same end result as invoking the NSObject method
> 'class'. Is it?
They are the same *if you are in a class method*.
If the above is in an instance method then no, they are not the same.
The first one will, in fact, never be true.
But if you're in a class method, then 'self' is the class. [self
class] == self in a class method, unless someone has overridden
+class.
Mike
_______________________________________________
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