I am trying to build a Multiplatform library: I he...
# multiplatform
c
I am trying to build a Multiplatform library: I heard in a few talks, that one of the advantages of Interfaces vs expect/actual is that you can write the implementation in Swift. For me, that works just fine if I am building a self contained app (Interface declared in common code, implementation inside of the iOS app in swift). But how would I bundle this implementation into a library? With my current approach, the user of the library would have to implement the swift implementation of the Interface themselves, which kind of defeats the purpose of a library in the first place.
r
I'm now realizing I've probably given that advice without being explicit enough about that limitation.
c
Are there other ways to import a pure swift library (without objc annotations) into a KMP library? I took a look at gitlive’s firebase library, but it seems like Firebase is published as an objC library, which they can import into KMP with carthage and a little bit of witchcraft. The other option that I found was

this video

, where he creates an objC wrapper around swift functions and then using it in KMP with cinterop. This does not seem sustainable for porting non-trivial swift libraries to KMP. Am I missing something here?
r
I don't think you're missing anything. It's just not a well-supported use-case. You definitely can't talk to Swift directly. It's always through an obj-c layer
c
That’s a bummer. That’s kind of a dealbreaker for me. To me, KMP as a platform should help me save time in comparison to two separate native solutions (Otherwise I would just do that). But without having access iOS dependencies, i don’t see how this is going to save me any time, at least for now 😕. And I don’t quite see how that is going to change in the future? It’s not like KMP libraries are going to pop up left and right if it’s not possible to integrate swift libraries. How are you imagining the future of KMP libraries?
r
You can generally be pretty flexible if you can keep everything on the Kotlin side. And you can talk to lots of iOS-specific stuff that way through cinterop. But it can be a bit of a shift of mindset compared to native iOS dev, and there's limitations when you need to cross the language boundary multiple times
direct Swift interop will probably happen eventually but it'll be a little while.
c
Thanks for the reply 👍 The concept behind KMP seems very promising to me, like having the best of both worlds (shared code, native UI). I am looking forward to future developments