Skip to content

Instantly share code, notes, and snippets.

@jakeheis
Last active December 15, 2015 01:59
Show Gist options
  • Save jakeheis/5183509 to your computer and use it in GitHub Desktop.
Save jakeheis/5183509 to your computer and use it in GitHub Desktop.
CKArgo - Makes dealing with a variable amount of arguments easy
#define CKArgoStart(first) \
va_list __block obscureNameNoOneShouldPick99; \
va_start(obscureNameNoOneShouldPick99, (first)); \
#define CKArgoArray(first) \
[NSMutableArray arrayWithObjectBlock:^id(NSInteger index) { \
if (index == 0) \
return str; \
id obj = va_arg(obscureNameNoOneShouldPick99, id); \
if (obj == self || !obj) { \
va_end(obscureNameNoOneShouldPick99); \
return nil; \
} \
return obj; \
}];
-(void)myAwesomeMethod:(NSString *)str, ... {
CKArgoStart(str);
NSArray *args = CKArgoArray(str);
NSLog(@"array %@", args);
}
-(void)caller {
[self myAwesomeMethod:@"first", @"second", @"third"]; // Will print: array (first, second, third)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment