Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holtwick/653105 to your computer and use it in GitHub Desktop.
Save holtwick/653105 to your computer and use it in GitHub Desktop.
- (void)test:(id)some second:(id)sec {
// Inspired by http://stackoverflow.com/questions/1797964/how-to-pass-all-arguments-of-a-method-into-nslog/1799472#1799472
{
// Find argument stack and skip first arguments
void *stack = &self;
stack += sizeof(self);
stack += sizeof(_cmd);
// Iterate through arguments
Method method = class_getInstanceMethod([self class], _cmd);
NSArray *parts = [NSStringFromSelector(method_getName(method)) componentsSeparatedByString:@":"];
NSString *output = @"Method called: [_";
for(unsigned i = 2; i < method_getNumberOfArguments(method); i++) {
char *argtype = method_copyArgumentType(method, i);
if(argtype[0] == '@') {
id o = stack;
// NSValue *v = [NSValue valueWithBytes:o objCType:argtype];
output = [output stringByAppendingFormat:@" %@:%@", [parts objectAtIndex:i - 2], *o];
stack += sizeof(id);
} else {
// Don't know how to handle it yet
break;
}
free(argtype);
}
NSLog(@"%@]", output);
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment