zoukankan      html  css  js  c++  java
  • OC中的一些编程写法--({"添加代码"}) 花括号用法

    self.tableView.tableHeaderView = ({
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 184.0f)];
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40, 100, 100)];
            imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
            imageView.image = [UIImage imageNamed:@"avatar.png"];
            imageView.layer.masksToBounds = YES;
            imageView.layer.cornerRadius = 50.0;
            imageView.layer.borderColor = [UIColor whiteColor].CGColor;
            imageView.layer.borderWidth = 3.0f;
            imageView.layer.rasterizationScale = [UIScreen mainScreen].scale;
            imageView.layer.shouldRasterize = YES;
            imageView.clipsToBounds = YESS;  
            [view addSubview:imageView];
            view;
        });

    这个问题严格上讲和Objective-C没什么太大的关系,这个是GNU C的对C的扩展语法 Xcode采用的Clang编译,Clang作为GCC的替代品,和GCC一样对于GNU C语法完全支持

    你可能知道if(condition)后面只能根一条语句,多条语句必须用{}阔起来,这个语法扩展即将一条(多条要用到{})语句外面加一个括号(), 这样的话你就可以在表达式中应用循环、判断甚至本地变量等。表达式()最后一行应该一个能够计算结果的子表达式加上一个分号(;), 这个子表达式作为整个结构的返回结果

    这个扩展在代码中最常见的用处在于宏定义中

  • 相关阅读:
    springmvc
    POJ 3683 Priest John's Busiest Day
    POJ 3678 Katu Puzzle
    HDU 1815 Building roads
    CDOJ UESTC 1220 The Battle of Guandu
    HDU 3715 Go Deeper
    HDU 3622 Bomb Game
    POJ 3207 Ikki's Story IV
    POJ 3648 Wedding
    HDU 1814 Peaceful Commission
  • 原文地址:https://www.cnblogs.com/mukekeheart/p/14547379.html
Copyright © 2011-2022 走看看