So I'm trying to check whether NSNumber
is Double
or Int
and I'm wondering if it's even possible.
I was hoping this will work, but it always returns true no matter with which type I'm comparing
var myDouble: Double = 0.0
var myNSNumber: NSNumber = NSNumber(value: myDouble)
if myNSNumber is Double {
print("NSNumber is Double")
}else {
print("NSNumber is different type")
}
In kotlin I'm using such Extension for Number which is NSNumber
in swift and I want to recreate it in swift
protected operator fun Number.plus(other: Number): Number {
return when (this) {
is Long -> this.toLong() + other.toLong()
is Int -> this.toInt() + other.toInt()
is Short -> this.toShort() + other.toShort()
is Byte -> this.toByte() + other.toByte()
is Double -> this.toDouble() + other.toDouble()
is Float -> this.toFloat() + other.toFloat()
}
}