I know that objective-c methods are actually c function, and that the first two arguments are self and _cmd. I’m trying to get the remaining arguments as an array (including or excluding, self and _cmd)
For example:
-(void)someMethod:(id)firstArg withObject:(id)secondArg andObject:(id)thirdArg {
//then something like:
args[0] //corresponds to self
args[1] //corresponds to _cmd
args[2] //corresponds to firstArg
args[3] //corresponds to secondArg
args[3] //corresponds to thirdArg
//or just start from firstArg being the 0th item in the index (skipping out self and _cmd)
}
What I’m trying to do is something like:
[self doOtherMethod:@selector(otherMethod:withObject:andObject:) withObjects:args];
So how can I get an array (c array or even NSArray) of the arguments passed to the method, so that I can pass them on or enumerate through them?
EDIT: I want to do this with existing methods, e.g. delegate methods that I can’t change.
The mechanism for argument-passing is architecture-dependent, and may involve passing values in registers, on the stack, or both. Trying to ferret out the list of arguments dynamically for anything other than debugging purposes is probably not a good idea, and certainly not portable.
Here’s an article that I think would be a great starting point for gaining more insight into how arguments are passed: http://en.wikipedia.org/wiki/Calling_convention