NSNumber(封装基本数据类型)

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

    //  
    //  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