1

As I know, in my overloaded method (in category) I may call [super method] to pass it to original class. In my case I don't have header file of class, so I write:

@interface OriginalClass : NSObject
@end

@interface OriginalClass (overloadMethod)
-(void) method;
@end

@implementation OriginalClass (overloadMethod)
-(void) method
{
    // some my code
    [super method]; // here is warning that "NSObject may not respond to '-method'
}
@end

So is it possible to pass method to OriginalClass correctly without having its header file? Maybe it would be better to look at method_setImplementation?

brigadir
  • 6,874
  • 6
  • 46
  • 81

2 Answers2

2

You're adding a category, not a subclass. When adding a category, think of it as tacking your own methods on to the existing class. Instead of sending messages to super (which in this case is NSObject), just send them to self. Imagine you're in the implementation of the class that you're adding a category to.

I'm not sure if you think you're subclassing or if you're trying to swizzle...

Mark Adams
  • 30,776
  • 11
  • 77
  • 77
  • 1
    Excuse my ignorance on this matter, but wouldn't `[self method]` amount to a recursive call of the same method? – Monolo Dec 09 '11 at 09:41
  • According to Apple docs `super` in categories means original class. The same question is discussed but not solved here: http://stackoverflow.com/questions/1405060/using-super-in-an-objective-c-category – brigadir Dec 09 '11 at 09:51
  • @Monolo Yes, it would. That's why I'm trying to figure out why you're overriding methods in a category. – Mark Adams Dec 09 '11 at 11:12
  • There is link to working solution in parallel thread (linked in my earlier comment): http://cocoawithlove.com/2008/03/supersequent-implementation.html It works! But some people on forums worry about deep hacking... – brigadir Dec 09 '11 at 15:25
1

If i remember correctly, the intro to ObjC programming in the docs mentions that when you override a method with a category, you can no longer access the original method.

Your question is pretty much identical to the one here: How do I call the original function from the overloaded function in a category?

Note the quote from the docs in the first answer

Community
  • 1
  • 1
Daniel
  • 1,079
  • 1
  • 11
  • 25