您的位置:首页 > 移动开发 > Objective-C

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

2016-04-25 14:53 295 查看


其中的主要好处是:

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: