开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜