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

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

  • 相关阅读:
    12.数组三--数组的冒泡排序与快速排序
    11.数组二
    10.数组一
    Vue之组件与父子传值
    Django模型层
    面向对象的组合用法
    面向对象初识
    Python内置函数
    列表推导式,生成器表达式
    装饰器进阶
  • 原文地址:https://www.cnblogs.com/mukekeheart/p/14547379.html
Copyright © 2011-2022 走看看