Paul Woitaschek
03/04/2021, 1:33 PMinternal 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.mbonnin
03/04/2021, 2:28 PMrusshwolf
03/04/2021, 2:37 PMconvert()
would still work in this case. But I might be missing something. There are edge cases where it's not what you want.Paul Woitaschek
03/04/2021, 3:21 PMrusshwolf
03/04/2021, 3:33 PMNSInteger
so you can do whatever conversion you need (convert()
, or some `expect`/`actual` that differs between 32-bit and 64-big sources) on the Kotlin side.