Re: Forcing allocation of a subclass
Re: Forcing allocation of a subclass
- Subject: Re: Forcing allocation of a subclass
- From: João Varela <email@hidden>
- Date: Sun, 25 Jan 2009 14:31:18 +0000
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?
JV
On 2009/01/25, at 14:07, Jean-Daniel Dupas wrote:
Le 25 janv. 09 à 14:50, João Varela a écrit :
Olá António
I think your method must be corrected like this:
On 2009/01/25, at 07:28, email@hidden wrote:
@implementation PDFDocument (PDFDocument_Alloc)
+ (id)replacementAllocWithZone:(NSZone *)zone
{
if ([self class] == [PDFDocument class]) {
return [ANPDFDocument replacementAllocWithZone:zone];
} else {
return [super allocWithZone:zone];
}
}
Note that you have to invoke the class method of self in order to
compare it properly. Otherwise you are comparing a pointer to a
class and the class name, which is the same as comparing apples
with oranges. For further information read the introspection
chapter in the Cocoa Fundamentals Guide:
'self' is a Class object as it's a class method, and +[NSObject
Class] also return a Class (and not a class name).
I don't understand the issues and saw nothing about it in the link
you provide.
http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_7.html
_______________________________________________
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