gpt4 book ai didi

ios - 这个方便是什么意思?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:08:42 25 4
gpt4 key购买 nike

_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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com