ios - What does this convenient mean? -


_labelview = ({     uiview * labelview = [[uiview alloc]initwithframe:cgrectmake(0, 0, _midview.frame.size.width, _midview.frame.size.height)];     (int = 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; }); 

why "labelview" can assignment this?

this statement expression, compound statement enclosed in parentheses, used expression. here gcc description of pattern:

a compound statement enclosed in parentheses may appear expression in gnu c. allows use loops, switches, , local variables within expression.

recall compound statement sequence of statements surrounded braces; in construct, parentheses go around braces. example:

({ int y = foo (); int z;     if (y > 0) z = y;     else z = - y;     z; }) 

is valid (though more complex necessary) expression absolute value of foo ().

the last thing in compound statement should expression followed semicolon; value of subexpression serves value of entire construct. (if use other kind of statement last within braces, construct has type void, , no value.)

the common use of statement expressions in #define macros (see gcc discussion), , it's not seen outside of context.


Comments