Why do enums turn into `KotlinEnum` in swift? Why ...
# multiplatform
e
Why do enums turn into
KotlinEnum
in swift? Why not a native enum?
m
I guess the Kotlin one has
.name
and
.values()
, etc... that the swift one doesn't have
There's no 1:1 mapping
m
Kotlin Native only creates Objective-C bindings and not Swift.
m
Right
I said "swift", I meant "obj-c" 🙂
I'm not sure what "obj-c" enums are but there is very little chance it has all the same behaviour as the Kotlin ones
m
I think they are much closer to C enums where there are grouped constants. No functions.
m
Yea exactly. Kotlin is a much richer language, there's a lot more than just a group of constants
If only because they have
.hashCode()
and
.equals()
e
If Swift bindings ever get supported, would it use swift enums?
m
Maybe
m
IIRC @kpgalligan said Swift bindings are most probably never going to happen at his talk in DroidCon last week 🙃
😭 2
🥲 4
m
Supporting Swift keeps getting pushed out on the road map, so I would not expect anything for a long time.
j
something to look out for in not too distant future is some work being done at TouchLab that will auto generate Swift adapter code. @kpgalligan also talked about that at little at Droidcon Berlin last week (https://speakerdeck.com/kpgalligan/sdk-design-and-publishing-for-kotlin-multiplatform-mobile?slide=102) ...don't know full details but seems promising
☝️ 2
🙏 2
k
Not never. Just delayed for a while. However, swift bindings won't "solve" all problems. Like sealed classes won't automatically become enums. That kind of thing. See the slides and hopefully the video soon.
👍 3
We're working on a thing to essentially compile and link swift into the kotlin framework. That should help generate a swift-assisted interface. There are other projects that do this, of course.
🤩 3
❤️ 5
s
@kpgalligan is there a roadmap available?
h
Swift and Kotlin Native both uses LLVM. I don't know anything about LLVM, but I hoped the LLVM IR is compatible, isn't it?
k
They're not automatically compatible, but direct interop is certainly possible. It'll happen at some point.
@samuele794 no hard roadmap. Proof of concept demoed at droidcon Berlin. If we can avoid unforseen issues, I think we'll be targeting droidcon NYC for at least private preview. We do need some feed back on what people want generated. Working on some features now, but the design isn't quite as straightforward s I'd assumed (but what ever is?)
💙 2
s
@kpgalligan I cheer for you and this concept
cheers 2
p
We use our swift generator that maps sealed classes and enums to enums for about half a year now and faced almost no issues so far. It's definitely doable. But ofc it's not in the shape of a library that has to fit all use cases - only ours.
👍 2