美文网首页
oc 旧版语法糖

oc 旧版语法糖

作者: 叩首问路梦码为生 | 来源:发表于2018-11-13 01:48 被阅读5次
    //
    //  ViewController.m
    //  OC 演练代码
    //
    //  Created by lzy on 2018/11/12.
    //  Copyright © 2018 lzy. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        UILabel *l=[UILabel alloc]initWithFrame:CGRectMake(0, 20, 100, 40);
        l.text=@"word";
        [self.view addSubview:l];
        
        // 拓展知识点
        UILabel *myLabel=({
            UILabel *l=[UILabel alloc]initWithFrame:CGRectMake(0, 280, 100, 40);
            l.text=@"word";
            [self.view addSubview:l];
            // l末尾给mylabel 设置数值;
            
            l;
        });
        
        NSLog(@"---%@",myLabel);
        
        
        
        // 花括号可以包装一段代码
        
        {
            UILabel *l=[UILabel alloc]initWithFrame:CGRectMake(0, 20, 100, 40);
            l.text=@"word";
            [self.view addSubview:l];
        }
        
    }
    
    
    -(void)demoSwith{
        int num=10;
        
        switch (num) {
            case 10:{
                NSString *name=@"张";
                NSLog(@"%@优秀",name);
                
                // 花括号限定变量的作用域名
            }
                
                
                break;
                
            default:
                  NSLog(@"一般");
                break;
        }
    }
    
    @end
    
    
    

    相关文章

      网友评论

          本文标题:oc 旧版语法糖

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