开发者

Obj-C Macro programming

开发者 https://www.devze.com 2023-02-11 04:27 出处:网络
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?

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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号