Is it possible to cast an NSInteger to NSNumber?
You cannot cast it because NSInteger
is not an object, just an alias for a built-in type. You can always create a new NSNumber
object from NSInteger
, like this:
NSNumber *myNum = @(myNsIntValue);
or in the prior version of the compiler, use
NSNumber *myNum = [NSNumber numberWithInteger:myNsIntValue];
since Apple LLVM Compiler 4.0
, there is an easier way to create NSNumber
object:
NSNumber *x = @1234;
NSNumber *y = @(anIntegerVariable);