//
// 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
网友评论