我正在尝试在Obj-c 运行时参考中找到的这种方法
BOOL class_addMethod(Class cls, SEL name, IMP imp, const char *types)
我想添加一个新方法,例如:
- [AClass drawWithFrame:(NSRect)rect inView:(id)view]
到目前为止,我已经编写了一个 C 函数:
void drawWithFrameInView(id this, SEL this_cmd, NSRect frame, id view){
...
}
现在我准备好了:
BOOL success = class_addMethod(NSClassFromString(@"AClass"),
@selector(drawWithFrame:inView:),
(IMP)drawWithFrameInView,
"v@:@:@:");
但success
绝不是肯定的,我尝试过使用具有更简单签名的方法的相同方法并且它有效。所以我认为问题是最后一个参数:"v@:@:@:"
在这种情况下我应该通过什么来让我的新方法起作用?