Bill Shiff
Bill Shiff

Reputation: 1429

Obj-C Macro programming

I'm trying to learn more about macro programming for Obj-C, as I have seen quite a bit of cool stuff done with it. Is it is possible to accomplish the following with a one-line macro?

MyNewViewController *newVC = [[MyNewViewController alloc] init];
[self.navigationController pushViewController:newVC animated:YES];
[newVC release];

Something like:

PushToNavController(@"MyNewViewController",YES);

Thanks

Upvotes: 2

Views: 418

Answers (1)

Dave DeLong
Dave DeLong

Reputation: 243156

Sure:

#define PushToNavController(_n,_a) { \
_n *__vc = [[(_n) alloc] init]; \
[self.navigationController pushViewController:__vc animated:(_a)]; \
[__vc release]; \
}

And then you'd use it like this:

PushToNavController(MyNewViewController, YES);

But.. why do you want to do this?

Upvotes: 5

Related Questions