美文网首页
代码中可能会看到的一些写法

代码中可能会看到的一些写法

作者: oh_flying | 来源:发表于2017-05-23 19:22 被阅读7次

有时候代码中有一些和我们平时看到的不一样,如下:

UILabel *l = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, 100, 40)];
l.text = @"hello";
[self.view addSubview:l];

{
    UILabel *l = [[UILabel alloc]initWithFrame:CGRectMake(0, 80, 100, 40)];
    l.text = @"world";
    [self.view addSubview:l];
}
//扩展知识点:要能看懂,在一些老的代码中会有
//{}包装代码,()表示执行
//工作中,看到的最多的表现是UITableView
UILabel *myLabel = ({
    UILabel *l = [[UILabel alloc]initWithFrame:CGRectMake(0, 280, 100, 40)];
    l.text = @"hello,world";
    [self.view addSubview:l];
    
    //最末尾的l会给myLabel设置数值
    l;
});

NSLog(@"%@",myLabel);

我只能说知道就好,没有什么高端的。

相关文章

网友评论

      本文标题:代码中可能会看到的一些写法

      本文链接:https://www.haomeiwen.com/subject/wpugxxtx.html