Objective-C GCC Code Block Evaluation C Extension ({…})语法

来源:互联网 发布:手机平面设计软件 编辑:程序博客网 时间:2024/05/17 07:56

这里写图片描述
其中的主要好处是:
1.在我将存储所生成的对象的实例变量是在第一行中,清楚地示出了代码的下一部分一样。在此之前,在分配发生在末端。
2.堆栈变量声明和使用在同一个函数/方法不污染其他代码。我可以随意使用非常通用名称(视图,框架,矩形,按钮),并没有得到与其他地区的冲突。

//一个GCC C扩展导致一个代码块self.helpButton = ({    // helpbutton  UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];  [button setImage:[UIImage imageNamed:@"ParentalControlQuestionMarkButton"]           forState:UIControlStateNormal];  CGRect buttonRect = innerBounds;  buttonRect.size = [button sizeThatFits:CGSizeMake(400, 400)];  buttonRect.origin.x = CGRectGetMaxX(innerBounds)-CGRectGetWidth(buttonRect);  button.frame = UIEdgeInsetsInsetRect(buttonRect, UIEdgeInsetsMake(0, -10, -20, -10));  [button addTarget:self action:@selector(helpAction:) forControlEvents:UIControlEventTouchUpInside];  [self addSubview:button];  button;});

更多文章:以下都是外网,我的电脑谷歌浏览器是可以打开的,我不知道你们打不打得开了
1. cocoa:http://cocoa-dom.tumblr.com/post/56517731293/new-thing-i-do-in-code
2.大胡子:http://nshipster.com/new-years-2014/
3.stack overflow : http://stackoverflow.com/questions/22023070/assignment-of-several-statements-enclosed-in-parentheses-and-curly-braces-in-obj
4.stack overflow : http://stackoverflow.com/questions/19732070/objective-c-declare-vars-with

0 0