- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
_labelView = ({
UIView * labelView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _midView.frame.size.width, _midView.frame.size.height)];
for (int i = 0;i < titleArr.count ; i++) {
[labelView addSubview:[self returnLabel:titleArr[i] andFrame:CGRectMake(0, i*_height, self.frame.size.width, _height) andColor:[UIColor whiteColor]]];
}
labelView;
});
为什么“labelView”可以这样赋值?
最佳答案
这是一个 statement expression , 括在圆括号中的复合语句,用作表达式。这是模式的 GCC 描述:
A compound statement enclosed in parentheses may appear as an expression in GNU C. This allows you to use loops, switches, and local variables within an expression.
Recall that a compound statement is a sequence of statements surrounded by braces; in this construct, parentheses go around the braces. For example:
({ int y = foo (); int z;
if (y > 0) z = y;
else z = - y;
z; })is a valid (though slightly more complex than necessary) expression for the absolute value of
foo ()
.The last thing in the compound statement should be an expression followed by a semicolon; the value of this subexpression serves as the value of the entire construct. (If you use some other kind of statement last within the braces, the construct has type void, and thus effectively no value.)
语句表达式最常见的用法是在 #define
宏中(参见 GCC discussion ),在该上下文之外并不常见。
关于ios - 这个方便是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34984243/
在javascript中,我可以这样写 console.log( person.name || person.nickname || '-' ) 然后会先查找name字段,如果找不到,会回退到nick
在为通用接口(interface)编写回调时,定义他们自己负责创建和访问的本地数据可能很有用。 在 C 中,我只使用一个空指针,类 C 示例: struct SomeTool { int ty
我是一名优秀的程序员,十分优秀!