Created
October 29, 2010 07:50
-
-
Save holtwick/653105 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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