How to convert Swift optional NSNumber to optional Int? (any improvements on my code?)
I think most easiest way is
var orderNumberInt = orderNum?.integerValue
Also,you can do it like this
var orderNum:NSNumber? = NSNumber(int: 12)
var orderNumberInt:Int? = (orderNum != nil) ? Int(orderNum!) : nil
print(orderNumberInt)
let number:NSNumber? = NSNumber(integer: 125)
if let integerValue = number?.integerValue {
print(integerValue)
}
let integerValue = number?.integerValue ?? 0