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
相关文章推荐
- Object.defineProperty 函数 (JavaScript)
- Objective-C字面量语法总结
- protocol的介绍与简单实用
- Cloneable接口和Object的clone()方法
- 缺少动态链接库: libthrift-0.9.3.so: cannot open shared object file: No such file or directory
- Objective-C Blocks 小测验
- Json工具类,实现了反射将整个Object转换为Json对象的功能,支持Hibernate的延迟加
- 将JsonObject转换成HashMap
- django-mvvm(django的FormObject)
- json-lib使用,JSONObject和JSONArray
- Android属性动画(一):ValueAimator和ObjectAnimator的基本使用
- java中的object... args参数
- php之PDO (PHP DATA OBJECT)
- objective-c IOS应用更新
- 使用JSONObject.fromObject的时候出现“There is a cycle in the hierarchy”异常 的解决办法
- iOS开发系列—Objective-C之Foundation框架
- json字符串转换为JSONObject和JSONArray .
- iOS开发系列--Objective-C之KVC、KVO
- Spring MVC 解决 Could not write JSON: No serializer found for class java.lang.Object
- iOS开发系列--Objective-C之类和对象