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;
}