Hey. I have an interesting Kotlin-Swift related is...
# multiplatform
a
Hey. I have an interesting Kotlin-Swift related issue šŸ˜„ Let’s say you have an enum in Kotlin:
Copy code
enum class SomeEnum(val id: String) { VALUE1("value1"), VALUE2("value2") }
which you can instantiate in your Kotlin code via
valueOf
method. How can I instantiate it in Swift code? Swift doesn’t see
valueOf
method. I’ve tried to add a compation object into an enum, to ā€œfakeā€
valueOf
method but its not visible on Swift side either. I guess workaround is to pattern match on Swift side, and just return an instance of
SomeEnum
case:
Copy code
switch valueInstance {
    case "value1": return .value1
    case "value2": return .value2
}
Are there any other solutions ? šŸ˜„
p
You can use the .values function and do the lookup yourself