[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A question about categories

From: Chris B. Vetter
Subject: Re: A question about categories
Date: Mon, 8 May 2006 12:05:28 +0200

On 5/5/06, Vaisburd, Haim <address@hidden> wrote:
I would like to override a method of an existing class.
One way is to create a category and define a method
with the same name, e.g.
@interface NSBitmapImageRep (MyCategory)
 - destroy;
Is there any way to call the original method
within the implementation of my override,
in this case the original [NSBitmapImageRep-destroy] ?

Try something like

static IMP originalDestroy;

@implementation NSBitmapImageRep (MyCategory)

+ (void) initialize
 Method_t destroy;
 static BOOL isInitialized = NO;

 [super initialize];
 if( isInitialized) return;

destroy = class_get_instance_method([NSBitmapImageRep class], @selector(destroy));

 originalDestroy = destroy->method_imp;

 isInitialized = YES;

void OriginalDestroy(id object)
 if( object) originalDestroy(object, @selector(destroy));

- (void) destroy


I do that to replace -description but with this I'm still able to use
the original


reply via email to

[Prev in Thread] Current Thread [Next in Thread]