Let's say I have an uninitialized variable:
UIViewController *vc;
From this variable, I want to reference UIViewController
, such that I could call alloc
or new
on it to return an instantiated object.
Essentially, I want to do:
UIViewController *vc = [*typeof(vc) new];
... which does not compile because the compiler expects an expression rather than a type.
If @encode
returned the actual type, I could do something like:
UIViewController *vc = [NSClassFromString(@(@encode(*typeof(vc)))) new];
...however, @encode
returns '@', which just means "generic object".
I realize it's a little philosophical in nature, but I get tired of typing and would like to make a macro like NEW(x)
. I also realize a similar macro could be made if it involves the actual declaration, but I am not satisfied with that syntax/angle.