discuss-gnustep
[Top][All Lists]
Advanced

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

Re: A question about categories


From: Richard Frith-Macdonald
Subject: Re: A question about categories
Date: Fri, 5 May 2006 20:07:58 +0100


On 5 May 2006, at 19:53, Vaisburd, Haim wrote:

Hi,

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;
@end

Is there any way to call the original method
within the implementation of my override,
in this case the original [NSBitmapImageRep-destroy] ?

No.
Or not simply anyway.
What you can do is put your new implementation in a loadable bundle, then get the method implementation before loading that bundle.

eg.

// This is the code in the bundle
@implementation NSBitmapImageRep (MyCategory)
static IMP old;
+ (void) setOldImplementation: (IMP)imp
{
  old = imp;
}
- (void) destroy
{
  // new code here
  (*old)(self, @selector(destroy));     // Invoke old implementation
}
@end

// And this is the code to set it up
IMP oldMethod = [NSBitmapImageRep instancemethodForSelector: @selector (destroy)];
// load bundle here
[NSBitmapImageRep setOldImplementation: oldMethod];







reply via email to

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