Re: Class introspection [was Re: Forcing allocation of a subclass]

2009-01-25 Thread João Varela
No, isKindOfClass check for the superclass. It returns true if self class is myClass or a subclass of myClass. You should use isMemberOfClass: to got something equivalent. Yes, you are right. Thanks for pointing it out. because in the first example we are calling -class: in [self class

Re: Class introspection [was Re: Forcing allocation of a subclass]

2009-01-25 Thread Jean-Daniel Dupas
Le 25 janv. 09 à 19:54, João Varela a écrit : On 2009/01/25, at 18:02, João Varela wrote: 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

Re: Class introspection [was Re: Forcing allocation of a subclass]

2009-01-25 Thread João Varela
On 2009/01/25, at 18:02, João Varela wrote: 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.

Re: Class introspection [was Re: Forcing allocation of a subclass]

2009-01-25 Thread mmalc Crawford
On Jan 25, 2009, at 10:02 AM, João Varela wrote: I think the following comparison is semantically wrong: if ( self == [MyClass class] ) mmalc __

Class introspection [was Re: Forcing allocation of a subclass]

2009-01-25 Thread João Varela
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 al

Re: Forcing allocation of a subclass

2009-01-25 Thread Michael Ash
On Sun, Jan 25, 2009 at 9:31 AM, João Varela 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 w

Re: Forcing allocation of a subclass

2009-01-25 Thread Jean-Daniel Dupas
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.

Re: Forcing allocation of a subclass

2009-01-25 Thread João Varela
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]"

Re: Forcing allocation of a subclass

2009-01-25 Thread Jean-Daniel Dupas
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, cocoa-dev-requ...@lists.apple.com wrote: @implementation PDFDocument (PDFDocument_Alloc) + (id)replacementAllocWithZone:(NSZone *)zone { if ([self cl

Re: Forcing allocation of a subclass

2009-01-25 Thread Jean-Daniel Dupas
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, cocoa-dev-requ...@lists.apple.com wrote: @implementation PDFDocument (PDFDocument_Alloc) + (id)replacementAllocWithZone:(NSZone *)zone { if ([self cl

Re: Forcing allocation of a subclass

2009-01-25 Thread João Varela
Olá António I think your method must be corrected like this: On 2009/01/25, at 07:28, cocoa-dev-requ...@lists.apple.com wrote: @implementation PDFDocument (PDFDocument_Alloc) + (id)replacementAllocWithZone:(NSZone *)zone { if ([self class] == [PDFDocument class]) { re

Re: Forcing allocation of a subclass

2009-01-24 Thread Antonio Nunes
On 24 Jan 2009, at 23:19, Jean-Daniel Dupas wrote: Calling the original implementation in a method you have exchanged is done using [self replacedMethodName] and in a method added at runtime, you have to call [super originalMethodName] [...] if you don't want to bother with the type string

Re: Forcing allocation of a subclass

2009-01-24 Thread Jean-Daniel Dupas
Le 24 janv. 09 à 22:13, Antonio Nunes a écrit : Sorry, sent this before I had finished making the necessary changes, I don't think I need to exchange any implementations if I add the method with the correct selector (allocWithZone:) === On 24 Jan 2009, at 19:20, Bill Bumgarner wrote: If

Re: Forcing allocation of a subclass

2009-01-24 Thread Antonio Nunes
Sorry, sent this before I had finished making the necessary changes, I don't think I need to exchange any implementations if I add the method with the correct selector (allocWithZone:) === On 24 Jan 2009, at 19:20, Bill Bumgarner wrote: If so, the method_exchangeImplementations() pattern wi

Re: Forcing allocation of a subclass

2009-01-24 Thread Antonio Nunes
On 24 Jan 2009, at 19:20, Bill Bumgarner wrote: If so, the method_exchangeImplementations() pattern will work. If not, you'll need to add the method to the class via class_addMethod(). Let's see if I understand this correctly: you mean I need to add alloc, or as suggested, allocWithZone: z

Re: Forcing allocation of a subclass

2009-01-24 Thread Jean-Daniel Dupas
Le 24 janv. 09 à 19:20, Bill Bumgarner a écrit : Thanks. I found that a few hours ago and was able to create the exchange. However, writing a correct replacement method is another thing altogether. The following doesn't work: Early in application startup: Method originalMethod = class_ge

Re: Forcing allocation of a subclass

2009-01-24 Thread Jean-Daniel Dupas
Le 24 janv. 09 à 19:20, Jean-Daniel Dupas a écrit : Le 24 janv. 09 à 18:51, Antonio Nunes a écrit : On 24 Jan 2009, at 18:09, Bill Bumgarner wrote: Or, more specifically, why do you want to make some bit of framework code which currently allocates an instance of A allocate an instance o

Re: Forcing allocation of a subclass

2009-01-24 Thread Jean-Daniel Dupas
Le 24 janv. 09 à 18:51, Antonio Nunes a écrit : On 24 Jan 2009, at 18:09, Bill Bumgarner wrote: Or, more specifically, why do you want to make some bit of framework code which currently allocates an instance of A allocate an instance of SubA instead? Because of, what I assume to be, a bu

Re: Forcing allocation of a subclass

2009-01-24 Thread Bill Bumgarner
On Jan 24, 2009, at 9:51 AM, Antonio Nunes wrote: On 24 Jan 2009, at 18:09, Bill Bumgarner wrote: Or, more specifically, why do you want to make some bit of framework code which currently allocates an instance of A allocate an instance of SubA instead? Because of, what I assume to be, a bug

Re: Forcing allocation of a subclass

2009-01-24 Thread Antonio Nunes
On 24 Jan 2009, at 18:09, Bill Bumgarner wrote: Or, more specifically, why do you want to make some bit of framework code which currently allocates an instance of A allocate an instance of SubA instead? Because of, what I assume to be, a bug in PDFClerkThumbnailView which when one drags m

Re: Forcing allocation of a subclass

2009-01-24 Thread Bill Bumgarner
On Jan 24, 2009, at 1:19 AM, Antonio Nunes wrote: I need to be able to force the requested allocation of a cocoa class to always return an instance of my subclass. I have looked into ways of doing that. First things first Why? Or, more specifically, why do you want to make some bit of

Re: Forcing allocation of a subclass

2009-01-24 Thread Mike Abdullah
I would recommend against the category approach. As your search of the archives no doubt explained, there's no guarantee that PDFDocument may at some point internally use its own category that would override yours. I don't know exactly how you'd do what you want (+poseAsClass: is deprecated