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];





_______________________________________________
Discuss-gnustep mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to