Too many arguments to function call, expected 0 method_invoke

1.1k views Asked by At

I'm trying to run the method id method_invoke ( id receiver, Method m, ... ); from the Objective-C runtime library but the compiler is saying I'm passing too many arguments, with it expecting 0. Why might this be? (swizzledMethodOriginalImplementation is of type Method)

-(NSMenu*) blah2: (NSEvent*)anEvent :(NSRect) cellFrame :(NSView*) aView { 
     NSMenu *contextMenu = method_invoke(self, swizzledMethodOriginalImplementation, anEvent, cellFrame, aView);
}
1

There are 1 answers

1
matt On BEST ANSWER

You're using method_invoke wrong. One must never actually call method_invoke directly. It doesn't know what arguments to expect. That is why its declaration, in the documentation, is written in a completely open-ended form:

id method_invoke ( id receiver, Method m, ... );

One must first cast the method_invoke function to the correct function pointer type for the method in question. I don't see you doing that.