_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/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |