NSNumber(封装基本数据类型)
2018-07-20 来源:open-open
// // main.m // OC05-task-04 // // Created by Xin the Great on 15-1-26. // Copyright (c) 2015年 Xin the Great . All rights reserved. // #import <Foundation/Foundation.h> int main(int argc, const charchar * argv[]) { @autoreleasepool { // insert code here... //////////////////////NSNumber////////////////////// //封装基本数据类型 int intValue = 100; float floatValue = 3.14; BOOL boolValue = YES; NSNumber *intNumber = [[NSNumber alloc] initWithInt:intValue]; NSLog(@"intNumber is %@", intNumber); NSNumber *floatNumber = [NSNumber numberWithFloat:floatValue]; NSLog(@"floatNumber is %@", floatNumber); NSNumber *boolNumber = [NSNumber numberWithBool:boolValue]; NSLog(@"boolNumber is %@", boolNumber); //包装之后就可以放到容器中 NSArray *arr = @[intNumber, floatNumber, boolNumber]; NSLog(@"arr is %@", arr); //还原成基本数据类型 float value = [floatNumber floatValue]; int value2 = [intNumber intValue]; NSLog(@"value is %.2f",value); NSLog(@"value2 is %d",value2); //快速创建的方法 NSNumber *intNum = @80;//----> NSNumber *intNumber = [[NSNumber alloc] initWithInt:80]; NSNumber *floatNum = @3.14;// ---->[NSNumber numberWithFloat:3.14]; NSNumber *boolNum = @YES;// ---> [NSNumber numberWithBool:YES]; NSNumber *charNum = @'a'; // ---> [NSNumber numberWithChar:'a']; //运算 NSNumber *number = @(1 + 2); //直接在数组中写 NSArray *arr1 = @[@"string", @12, intNum, floatNum, boolNum, charNum, number]; NSLog(@"arr1 is %@", arr1); } return 0; }
来自:http://blog.csdn.net/zuojx1013/article/details/43202413
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:C# 两个目录同步的代码
最新资讯
热门推荐