PassKit PassKit - 1 year ago 117
Swift Question

How to cast from UInt16 to NSNumber

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'


How can I recast this as an NSNumber?

Answer Source
var castAsNSNumber = NSNumber(unsignedShort: myUInt16)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download