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

后端 未结 11 1428
情话喂你
情话喂你 2020-12-12 18:55

This compiles/works fine with Xcode 5, but causes a compile error with Xcode 6 Beta 4:

objc_msgSend(anItem.callback_object,
NSSelectorFrom         


        
相关标签:
11条回答
  • 2020-12-12 19:22

    Just to spare watching a WWDC video, the answer is you need to strong type objc_msgSend for the compiler to build it:

    typedef void (*send_type)(void*, SEL, void*);
    send_type func = (send_type)objc_msgSend;
    func(anItem.callback_object, NSSelectorFromString(anItem.selector), dict);
    

    Here is another sample when calling instance methods directly, like this:

    IMP methodInstance = [SomeClass instanceMethodForSelector:someSelector];
    methodInstance(self, someSelector, someArgument);
    

    Use strong type for methodInstance to make LLVM compiler happy:

    typedef void (*send_type)(void*, SEL, void*);
    send_type methodInstance = (send_type)[SomeClass instanceMethodForSelector:someSelector];
    methodInstance(self, someSelector, someArgument);
    

    Do not forget to set send_type's return and argument types according to your specific needs.

    0 讨论(0)
  • 2020-12-12 19:27

    This could also be caused by running pod install using Cocoapods 0.36.beta.2. I have reported the issue to CocoaPods. "Workaround" by using CocoaPods 0.35

    0 讨论(0)
  • 2020-12-12 19:30

    I was getting this error with QuickDialog. Following on to james_alvarez's answer but for AppCode, go to Project Settings, then click on QuickDialog under Project/Shared Settings, scroll down to ENABLE_STRICT_OBJC_MSGSEND and enter NO for Debug and Release.

    0 讨论(0)
  • 2020-12-12 19:31

    If you think having to do this is annoying and pointless you can disable the check in the build settings by setting 'Enable strict checking of objc_msgSend Calls' to no

    0 讨论(0)
  • 2020-12-12 19:32

    Setting Enable strict checking of objc_msgSend Calls to NO, solved my issue. Below is the screenshot

    0 讨论(0)
  • 2020-12-12 19:33

    This block of code reproduces the error:

    - (void)reportSuccess:(void(^)(void))success
    {
        success(what_is_this);
    }
    

    Guess where error is? Of course, what_is_this is not declared, but somehow magically it shows another error. In other words looks like if you have block, you can put any parameters when calling it, even non existent variables.

    0 讨论(0)
提交回复
热议问题