How to cast from UInt16 to NSNumber

半腔热情 提交于 2019-12-06 20:34:50

问题


I have a UInt16 variable that I would like to pass to a legacy function that requires an NSNumber.

If I try:

var castAsNSNumber : NSNumber = myUInt16

I get a compiler error 'UInt16' is not convertible to 'NSNumber'

Question

How can I recast this as an NSNumber?


回答1:


var castAsNSNumber = NSNumber(unsignedShort: myUInt16)


来源:https://stackoverflow.com/questions/24134716/how-to-cast-from-uint16-to-nsnumber

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!