Objective-C:NSNumber类的常见用法

NSNumber基本数据类型包装类:

//

//  main.m

//  04-NSNumber

//

//  Created by ma c on 15/8/17.

//  Copyright (c) 2015年. All rights reserved.

//

 

#import <Foundation/Foundation.h>

 

int main(int argc, const char * argv[])

{

    @autoreleasepool

    {

        //NSNumber的测试(基本数据包装类)

        NSNumber *number1 = @10;

        NSNumber *number2 = @12.34;

        

        NSNumber *number3 = [NSNumber numberWithChar:'A'];

        NSNumber *number4 = [NSNumber numberWithBool:NO];

        

        char c = [number3 charValue];

        int ci = [number3 intValue];

        NSLog(@"c = %c",c);

        NSLog(@"ci = %d",ci);

        

        BOOL b = [number4 boolValue];

        NSLog(@"b = %d",b);

        

        double d = [number2 doubleValue];

        NSLog(@"d = %lf",d);

        

        int i = [number2 intValue];

        NSLog(@"i = %i",i);

        

    }

    return 0;

}

 

posted @ 2015-08-17 19:19  XYQ全哥  阅读(158)  评论(0编辑  收藏  举报