OC中的NSNumber

 1 //声明一个整数
 2     NSInteger a=9;
 3     //创建常见的数据类型的对象
 4     NSNumber *intNumber=[[NSNumber alloc] initWithInt:5];
 5     NSNumber *floatNumber=[[NSNumber alloc] initWithFloat:5.14f];
 6     NSNumber *doubleNumber=[[NSNumber alloc] initWithDouble:5.14];
 7     NSNumber *charNumber=[[NSNumber alloc] initWithChar:'C'];
 8     
 9     //NSNumber是一个类簇,可以创建各种数据类型的对象
10     
11     NSNumber *intNumber=[NSNumber numberWithInt:6];
12     //比较是否相等:不同类型之间也可以相比较
13     BOOL ret=[intNumber isEqualToNumber:intNumber2];
14     BOOL ret=[intNumber isEqualToNumber:floatNumber];
15     //比较大小:
16     if([intNumber compare:intNumber2]==NSOrderedAscending){
17         NSLog(@"<");
18     }else if([intNumber compare:intNumber2]==NSOrderdSame)
19     {
20         NSLog(@"=");
21     }else if([intNumber compare:intNumber2]==NSOrderdDescending){
22         NSLog(@">");
23     }
24     //输出
25     NSLog(@"%d",[intNumber intValue]);
26     NSLog(@"%f",[floatNumber floatValue]);
27     NSLog(@"%f",[doubleNumber doubleValue]);
28     NSLog(@"%c",[charNumber charValue]);
29     //释放
30     [intNumber release];
31     [floatNumber release];
32     [dobuleNumber release];
33     [charNumber release];

 

posted @ 2015-06-08 21:32  海东青飞吧!  阅读(272)  评论(0编辑  收藏  举报