[Top][All Lists]

[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:


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

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.


// 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

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