We're hoping to use Kotlin-native across our iOS and Android apps to share business logic. The Android app uses data classes for its entities, the iOS app uses structs. Our initial plan was to have each set of platform specific entities implement an interface/protocol defined in kotlin-native. The shared business logic would never know whether it's operating on a struct or a data class.
The problem we're facing is that Swift structs cannot conform to the objc protocols that kotlin-native generates. Is there any way around this, short of adding support for Kotlin to Swift compilation? On that note, is Kotlin to Swift compilation a possibility, on the roadmap, or a goal of this project?
Is there any way around this
I don't think so.
is Kotlin to Swift compilation a possibility, on the roadmap, or a goal of this project?
We are considering options in this direction, but there鈥檚 no publicly available decision so far.
Why do you need structs conforming Kotlin protocols? What's your motivation behind using structs instead of classes here?
Thanks for the fast response.
What's your motivation behind using structs instead of classes here?
We've implemented a (mostly) platform agnostic redux-like architecture for both of the apps. We decided on Structs for iOS primarily due to the performance benefits and the built-in copy on write functionality that's utilized heavily by redux.
The existing iOS app is 100% Swift so the key concern of our iOS devs is whether the benefits of code sharing will outweigh the loss of Swift language features and the ongoing tax of adding Objective-C to the codebase.
We are considering options in this direction, but there鈥檚 no publicly available decision so far.
This is exciting, Kotlin to Swift would be amazing. We'd very likely be onboard if this happens. The challenge for us is timing, is there anything you can share about when a decision is likely to be made?
Makes sense, thank you.
is there anything you can share about when a decision is likely to be made?
I can't give any promises on this. It still needs some research.
This has been a fairly big topic in our work too. We've been discussing some less elegant solutions. For example, annotated data classes (with restrictions) would trigger Swift code gen for equivalent structs, translation code, and Swift extension methods. We've done zero actual work on this so far, so can't say it would be useful or performant.
Taking a step back, there is a perception in Swift-focused teams that Kotlin libraries are basically Objc, and there's a lot of resistance as a result. Making Kotlin interop more appealing to iOS devs is basically what I'm focused on now, so I'm super interested in any progress here.
To clarify something above, by "Kotlin to Swift compilation" do you mean ABI stability and direct interop, or something else?
This has been a fairly big topic in our work too.
Glad to hear other teams are looking into the problem too. Annotating data classes sounds promising. Are you planning to try this approach? Perhaps I can help out.
do you mean ABI stability and direct interop...
Yes exactly, thanks for clarifying.
It's been discussed, but current focus is on other things. All of my plans are in this context. That currently includes getting experimental generics support in, and enabling Kotlin debugging in Xcode. We've discussed data classes/structs, but not sure when that'll actually start or if that will be a priority, but I can say they definitely want them :)
If you're interested, I'd love to have a quick chat about your plans and resistance you're running into.
Yeah i've read some of your recent posts, great stuff.
quick chat about your plans and resistance you're running into.
Sure thing, i'll follow up via email.
Most helpful comment
This has been a fairly big topic in our work too. We've been discussing some less elegant solutions. For example, annotated data classes (with restrictions) would trigger Swift code gen for equivalent structs, translation code, and Swift extension methods. We've done zero actual work on this so far, so can't say it would be useful or performant.
Taking a step back, there is a perception in Swift-focused teams that Kotlin libraries are basically Objc, and there's a lot of resistance as a result. Making Kotlin interop more appealing to iOS devs is basically what I'm focused on now, so I'm super interested in any progress here.
To clarify something above, by "Kotlin to Swift compilation" do you mean ABI stability and direct interop, or something else?