ios convert int to NSObject
in my function I have a parameter of NSObject* type, to allow to pass NSString, NSDate, etc.. and intenally do something... I need to pass开发者_如何学C also a value of type int.. how can I do this?
thanks
You can use the NSNumber
class (http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/Reference/Reference.html), and initialize it with the numberWithInt
method.
@Itamar's answer is sufficient, but I'm just simplifying it.
Try this,
NSNumber *your_object = [NSNumber numberWithInt:int_value];
So now int_value is converted into object.
精彩评论