美文网首页
升级Xcode12后,objc_msgSend爆红

升级Xcode12后,objc_msgSend爆红

作者: 曾经像素有点低 | 来源:发表于2020-12-01 12:55 被阅读0次

Too many arguments to function call, expected 0, have 3
报错截图如下:

Too many arguments to function call, expected 0, have 3.jpeg

1.网上查询的方法如下,但是没用:

Build Settings->Apple Clang - Preprocessing->Enable Strict Checking of objc_msgSend Calls 为NO。
我的项目已经设置就是NO了

2.最终解决方法:

objc_msgSend函数是无返回参数的函数,需要把它强制转化类型

id scheduleVc = ((id (*)(Class _Nullable, SEL _Nonnull,
 SEL _Nonnull))(void *)objc_msgSend)(objc_getClass("ScheduleViewController"), 
sel_registerName("alloc"), sel_registerName("init"));

3.解释

((id (*)(Class _Nullable, SEL _Nonnull, SEL _Nonnull)).jpeg

1.变量scheduleVc是id类型,所以需要
   强转(objc_msgSend函数)返回id类型的值
   所以是 id (*)


2.函数中的三个参数:
   a.是Class类型的
   b.是SEL类型的
   c.也是SEL类型的
   所以是 (Class, SEL, SEL)


3. (   (id (*)(Class, SEL,SEL))(void *)   objc_msgSend  )

参考作者:聆听随风 的这篇文章https://www.jianshu.com/p/6dc96c13f58a

相关文章

网友评论

      本文标题:升级Xcode12后,objc_msgSend爆红

      本文链接:https://www.haomeiwen.com/subject/irqswktx.html