Hi guys, I’m having trouble doing a `switch` state...
# ios
m
Hi guys, I’m having trouble doing a
switch
statement with Kotlin/Native enums in Objective-C. I’m getting the error
Statement requires expression of integer type ('NtvCoreRateType *' invalid)
. It seems that Kotlin enum classes don’t get converted into proper enums in objective-C, so I’m wondering if its at all possible to do a switch statement with them? And if not, what is the expected way to compare them?
n
In Swift it’s sorta possible to switch over enum classes (albeit it won’t be exhaustive, requiring a
default:
clause), but in Obj-C, as far as my understanding goes, you’d have to resort to if-else if…. There’s a ticket to expose “raw” enum values to Obj-C/Swift though: https://youtrack.jetbrains.com/issue/KT-48068/Native-Feature-Request-Add-typed-ordinal-for-enums-bridged-to-Obj-C Hopefully it will get some love one day.
m
Ah, as I feared. Not the worse problem in the world. Thanks for response!
n
You're welcome! On the second thought, the ordinal property mentioned in the ticket might do the trick for you.
m
ya, I tried that too. It didn’t work since for the
case
statements though, since it wants the values to be constants, and it doesn’t see recognize the values from KotlinEnum as constants