in xcode6 gold master, using objc_msgSend now throws a syntax error saying the number of arguments is wrong

后端 未结 2 768
离开以前
离开以前 2020-12-14 10:10
 id topLayoutGuideObj = objc_msgSend(viewController, @selector(myselector));

\"Too many arguments to function call, expected 0, h

相关标签:
2条回答
  • 2020-12-14 10:23

    See just a few lines above you referred.

     /* 
      * ...
      *
      * These functions must be cast to an appropriate function pointer type 
      * before being called. 
      */
    

    You can call it like:

    #import <objc/runtime.h>
    #import <objc/message.h>
    
    id<MyProtocol> topLayoutGuideObj = ((id (*)(id, SEL))objc_msgSend)(viewController, @selector(myselector));
    

    OR

    id (*typed_msgSend)(id, SEL) = (void *)objc_msgSend;
    id<MyProtocol> topLayoutGuideObj = typed_msgSend(viewController, @selector(myselector));
    
    0 讨论(0)
  • 2020-12-14 10:34

    I have checked it out, the main problem was as @Jerry Krinock said in comment of accepted answer;

    1. Go to your project Build Settings
    2. Search for objc_msgSend
    3. Set its value to "No" instead of "Yes"
    0 讨论(0)
提交回复
热议问题