Hi all. Would you recommend using sealed classes i...
# touchlab-tools
p
Hi all. Would you recommend using sealed classes in multiplatform project? Afaik on iOS there is no concept of sealed class, so I’m wondering how swift/objective c code can be integrated with Kotlin/Native code that is taking sealed class as an argument/returning it.
r
The more you can keep that logic on the Kotlin side, the more you'll be able to leverage Kotlin features. One trick is to do the
when
in Kotlin and pass lambdas from Swift for the Kotlin to trigger. KaMPKit does that for example here: https://github.com/touchlab/KaMPKit/blob/master/shared/src/iosMain/kotlin/co/touchlab/kampkit/NativeViewModel.kt#L53-L70 More generally, I would avoid trying too hard to force Swift to do things in a Kotlin style. Swift is its own language and the Swift and iOS communities have patterns and best practices for what works well in that code.
🎉 1
👏 1
p
We map the public api of our libraries to swift at a centralized place
Usually we translate a sealed class to a swift enum