To simplify, let's say I have a function like that
void myFunc(id _self, SEL _cmd, id first, ...)
{
}
In that method I wanna call the implementation(imp) on the superclass of _self. I can reach that IMP with this code:
Class class = object_getClass(_self);
Class superclass = class_getSuperClass(class);
IMP superimp = class_getMethodImplementation(superclass, _cmd);
now, how can I do to call that imp ?
This argument that can accept variable number of values is called varargs. In order to define vararg, ... (three dots) is used in the formal parameter of a method. A method that takes variable number of arguments is called a variable-arity method, or simply a varargs method.
With Python, we can use the *args or **kwargs syntax to capture a variable number of arguments in our functions. Using *args , we can process an indefinite number of arguments in a function's position.
A variable-length argument is a feature that allows a function to receive any number of arguments. There are situations where a function handles a variable number of arguments according to requirements, such as: Sum of given numbers. Minimum of given numbers and many more.
Just call it using variable arguments:
superImp(self, _cmd, argument1, argument2, argument3, etc...)
IMP is already typedef
'd as
typedef id (*IMP)(id, SEL, ...);
So you can call it with variable arguments with no issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With