You can create an NSNumber object with integer value by calling NSNumber
numberWithInt method. NSNumber is an general container object for any number(integer, float, double...). Note that NSNumber
numberWithInt method returns an autoreleased object. Unless the number is retained, it will go away after AutoReleasePool is drained. [NSNumber
numberWithInt example]
#import <Foundation/Foundation.h>
int
main(
int
argc,
char
*argv[])
{
NSAutoreleasePool *pool = [NSAutoreleasePool
new
];
NSNumber *objNum;
NSInteger n;
objNum = [NSNumber numberWithInt:100];
n = [objNum integerValue];
NSLog(@
"n:%i"
,n);
objNum = nil;
objNum = [[NSNumber alloc]initWithDouble:0.7];
NSLog(@
"number:%f"
, [objNum doubleValue]);
[objNum release];
[pool drain];
return
0;
}