Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xcode

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

objc_msgSend(anItem.callback_object,
NSSelectorFromString(anItem.selector), dict);

This is a 3rd-party component, so while I have the source code, it's not really my code and I'm hesitant to change it much (despite my personal opinion of 'wtf why are they using objc_msgSend??').

Image with possibly useful detail (error in error browser): enter image description here

like image 219
Alex the Ukrainian Avatar asked Jul 23 '14 23:07

Alex the Ukrainian


4 Answers

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

like image 127
James Alvarez Avatar answered Nov 06 '22 22:11

James Alvarez


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.

like image 20
Vladimir Grigorov Avatar answered Nov 06 '22 22:11

Vladimir Grigorov


I found the answer, and it's in Session 417 from 2014 WWDC "What's New in LLVM". If you find this code in a 3rd party library, such as Apsalar, updating to the latest version fixes it (probably because it's not distributed as a lib, ha). For an example of casting of these calls, see THObserversAndBinders library - I'm using it and noticed that the author updated the code, such as here:

https://github.com/th-in-gs/THObserversAndBinders/blob/master/THObserversAndBinders/THObserver.m

like image 23
Alex the Ukrainian Avatar answered Nov 06 '22 22:11

Alex the Ukrainian


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

like image 20
Maciej Swic Avatar answered Nov 06 '22 23:11

Maciej Swic