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

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

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

2条回答
  •  Happy的楠姐
    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 
    #import 
    
    id topLayoutGuideObj = ((id (*)(id, SEL))objc_msgSend)(viewController, @selector(myselector));
    

    OR

    id (*typed_msgSend)(id, SEL) = (void *)objc_msgSend;
    id topLayoutGuideObj = typed_msgSend(viewController, @selector(myselector));
    

提交回复
热议问题