cinnamonraisin
cinnamonraisin

Reputation: 83

Too many arguments to function call, expected 0 method_invoke

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);
}

Upvotes: 3

Views: 1118

Answers (1)

matt
matt

Reputation: 534925

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.

Upvotes: 1

Related Questions