I have this macro that detects if a variable is an object:
#define IS_OBJECT(x) ( strchr("@#", @encode(typeof(x))[0]) != NULL )
#define AUTO_BOX(x) IS_OBJECT(x) ? x : @(x)
I wanted to simplify my workflow by auto box any primitives so that I can quickly do something like this:
BOOL v1 = YES;
id v2 = [[NSObject alloc] init];
NSLog(@"%@ %@", AUTO_BOX(v1), AUTO_BOX(v2));
//the @"%@ %@" format is non-changeable, I can't change them to @"%d %@" or @"%x %@"
This of course will throw error for v2 since it's an object:
error: illegal type 'id' used in a boxed expression
What could I do to fix this?