在调用IPM的时候报了`Too few arguments to function call, expected at least 2, have 0`的错

来源:4-1 类方法和实例方法之间的区别

风儿想嚯奶茶

2019-03-06

我在学习的时候,按照老师的示例代码,

@interface TestClass : NSObject
//
-(void)testLog;
//
+(void)testLog;
@end
//=============================== 实例方法
SEL sel = @selector(testLog);
IMP imp = class_getMethodImplementation([TestClass class], sel);
imp();
//=============================== 类方法
SEL testSel = @selector(testLog);
NSString *className = [NSString stringWithFormat:@"%s",class_getName([TestClass class])];
NSLog(@"className===============%@",className);
IMP testImp = class_getMethodImplementation(objc_getMetaClass(class_getName([TestClass class])), testSel);
testImp();

编译的时候报错:

Too few arguments to function call, expected at least 2, have 0

Wrong

我设置objc_msgSend为NO,还是会报这个错。
设置
Stack Overflow上提问,但目前没有人给出解决方案,请问这个造成这个错误的原因是什么呢,应该如何解决。

写回答

1回答

风儿想嚯奶茶

提问者

2019-03-06

问题解决了,修改`objc_msgSend`为YES,就OK了。

0
1
逆风
好的。
2019-03-07
共1条回复

面试跳槽提升必备 全面解析iOS中的Runtime机制

高薪职位,复杂业务需求,高性能APP,Runtime技术不可不学。

275 学习 · 48 问题

查看课程