I ran into real weirdnesses with an combined apple source set for watchos and ios because the NSInteger is a long on ios and an int on watchos.
This made me write really strange code like this:
Copy code
internal fun NSInteger.toInt(): Int {
return asInt()
}
private fun Any.asInt(): Int {
return when (this) {
is Long -> this.toInt()
is Int -> this
else -> error("Could not convert $this to Int")
}
}
Is there a better way to do that? I’m kind of looking for the opposite of cinterop.convert.