开发者

ios convert int to NSObject

开发者 https://www.devze.com 2023-02-04 06:28 出处:网络
in my function I have a parameter of NSObject* type, to allow to pass NSString, NSDate, etc.. and intenally do something...

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

精彩评论

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

关注公众号