Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to cast an NSInteger to NSNumber?

Is it possible to cast a NSInteger to a NSNumber object?

I need to convert the tag of a UIImageView object to a NSNumber object because I need to pass it as an argument to a function.

like image 604
Fitzy Avatar asked Mar 14 '12 07:03

Fitzy


1 Answers

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]; 
like image 147
Sergey Kalinichenko Avatar answered Oct 05 '22 22:10

Sergey Kalinichenko