1

I encountered the following code in others' project:

_titleLabel = ({
        UILabel *label = [UILabel new];
        label.translatesAutoresizingMaskIntoConstraints = NO;
        label.lineBreakMode = NSLineBreakByTruncatingTail;
        label.adjustsFontSizeToFitWidth = YES;
        label.textAlignment = NSTextAlignmentLeft;
        label.numberOfLines = 1;
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont fontWithName:@"HelveticaNeue" size:14.0f];
        label;
    });

See this usage for the first time, what is it about?

Leo
  • 492
  • 1
  • 5
  • 15
  • Look's like _titleLabel will have that label. – Cy-4AH Aug 27 '15 at 13:43
  • This is using the block syntax to offset the scope, so that you can define the labels as you would, possibly multiple different labels, without having to change the name of the inline `UILabel` variable -- making it easier to copy and past the code (is that a good thing?) – TZHX Aug 27 '15 at 13:45
  • 1
    See [Statements and Declarations in Expressions](https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html). – Mats Aug 27 '15 at 13:49
  • @TZHX Nope. A block should start with a ^ – Leo Aug 27 '15 at 14:47
  • @Mats Yeah you're right. Sorry to find a similar question TAT. – Leo Aug 27 '15 at 14:48

0 Answers0