I am trying this method found in Obj-c runtime reference
BOOL class_addMethod(Class cls, SEL name, IMP imp, const char *types)
I want to add a new method like:
- [AClass drawWithFrame:(NSRect)rect inView:(id)view]
So far I have written a C function:
void drawWithFrameInView(id this, SEL this_cmd, NSRect frame, id view){
...
}
now I am ready to do:
BOOL success = class_addMethod(NSClassFromString(@"AClass"),
@selector(drawWithFrame:inView:),
(IMP)drawWithFrameInView,
"v@:@:@:");
but success is never YES, I have tried the same approach with methods with simpler signatures and it worked. So I think the problem is last parameter: "v@:@:@:"
What should I pass in this case to get my new method working ?
selfand_cmd, so you can write the same code you would have written in a method?selfand_cmdare supposed to be normal parameters. I didn't like the fact that a parameter was colored as keywords in Obj-C (even though they represent those keywords). That is all :)