ios高效开发-使用字面量语法让iOS代码更简洁漂亮
2016-01-25 14:56
453 查看
NSNumber *nInt = @1; NSNumber *nFloat = @1.1; NSNumber *nDouble = @1.1111111; NSNumber *nBool = @YES; NSNumber *nChar = @'a'; NSLog(@"nInt : %@",nInt); NSLog(@"nFloat : %@",nFloat); NSLog(@"nDouble : %@",nDouble); NSLog(@"nBool : %@",nBool); NSLog(@"nChar : %@",nChar); int a = 5; int b = 6; NSNumber *nExpression = @(a*b); NSLog(@"nExpression : %@",nExpression); NSArray *array1 = @[@"1",@"2",@"3",@"4",@"5"]; NSArray *array2 = @[@1,@2,@3,@4,@5]; NSLog(@"array1 : %@",array1); NSLog(@"array2 : %@",array2); NSLog(@"array1-1 : %@",array1[1]); NSLog(@"array2-2 : %@",array2[2]); NSDictionary *dict1 = @{@"name":@"wangdalei",@"age":@26,@"sex":@"男"}; NSLog(@"dict1 : %@",dict1); NSLog(@"dict1[@\"name\"] : %@",dict1[@"name"]); NSMutableDictionary *dict2 = [[NSMutableDictionary alloc]initWithDictionary:@{@"name":@"wangdalei",@"age":@26,@"sex":@"男"}]; dict2[@"name"] = @"moxi90"; dict2[@"age"] = @90; NSLog(@"dict2[@\"name\"] :%@",dict2[@"name"]); NSLog(@"dict2[@\"age\"] : %@",dict2[@"age"]);
输出日志:
2016-01-25 14:51:39.136 WDLClock[2728:396830] nInt : 1 2016-01-25 14:51:39.136 WDLClock[2728:396830] nFloat : 1.1 2016-01-25 14:51:39.137 WDLClock[2728:396830] nDouble : 1.1111111 2016-01-25 14:51:39.137 WDLClock[2728:396830] nBool : 1 2016-01-25 14:51:39.137 WDLClock[2728:396830] nChar : 97 2016-01-25 14:51:39.137 WDLClock[2728:396830] nExpression : 30 2016-01-25 14:51:39.137 WDLClock[2728:396830] array1 : ( 1, 2, 3, 4, 5 ) 2016-01-25 14:51:39.138 WDLClock[2728:396830] array2 : ( 1, 2, 3, 4, 5 ) 2016-01-25 14:51:39.138 WDLClock[2728:396830] array1-1 : 2 2016-01-25 14:51:39.138 WDLClock[2728:396830] array2-2 : 3 2016-01-25 14:51:39.138 WDLClock[2728:396830] dict1 : { age = 26; name = wangdalei; sex = "\U7537"; } 2016-01-25 14:51:39.138 WDLClock[2728:396830] dict1[@"name"] : wangdalei 2016-01-25 14:51:39.138 WDLClock[2728:396830] dict2[@"name"] :moxi90 2016-01-25 14:51:39.139 WDLClock[2728:396830] dict2[@"age"] : 90
再添加一个关于Mutable的变量的声明:
NSMutableArray *ar3 = [@[@"2",@"6",@"5",@"4",@"3"] mutableCopy]; NSMutableDictionary *dic3 = [@{@"xxxx":@"2",@"wwww":@"w",@"eeee":@"e",@"rrrr":@"r"} mutableCopy];
相关文章推荐
- ios获取存储空间
- iOS重绘机制drawRect
- iOS 在viewController中监听Home键触发以及重新进入界面的方法
- iOS--BaiduMap自定义annotation和annotationView
- iOS获取系统时间
- iOS中解析Bonjour服务(转)
- IOS-应用之间调用
- iOS 给【控制器添加统计】的简单、使用方法
- iOS7计算文本尺寸
- IOS 真机报错,dyld:Librarynotloaded;image not found
- iOS 多个按钮选中一个
- iOS CATextLayer 富文本
- ios应用版本号设置规则
- IOS支付宝开发中的问题
- IOS支付宝开发SDK的集成
- iOS:控制器间的数据传递
- iOS第三方类库JSPatch(热更新)
- iOS文件写入读取
- IOS自定义控件系统方法调用顺序
- iOS 中如何添加应用自己的字体,使用萍方体