Alex Apriamashvili
03/18/2025, 8:58 PMsealed class
in Kotlin is probably better to be limited to the Android specific code only as we can't really get any benefit from it on iOS. While Swift has parametrised enums, the glue layer between KMM and Swift code is Objective C which has no clue of what a sealed class or an enum case with parameters is. One possible workaround we identified was to use open class
with corresponding subclasses in Kotlin that allows similar pattern matching on both platforms, yet implies certain risks when used at scale.
My question is rather complex, but let me put it this way:
• Are we on the right track or should we reconsider our approach to sharing code in any way?
• What are some other known limitations that we should keep in mind when sharing logic (better yet data structures and method signatures) across different platforms?
• Do we need to worry about Swift Strict Concurrency in any way? (Haven't yet tested the solution against some of our Swift 6 packages)
Appreciate any insights and help!
Thank youTheArchitect123
03/18/2025, 9:09 PMJason
03/19/2025, 3:59 PMswitch onEnum(of:) { }.
I think your on the right track for sharing code, I fully committed to using KMP for sharing all the code in our apps minus obviously the SwiftUI/Compose rendering layer. This includes shared ViewModels, its really nice if you can write all your new code in KMP, very little issues if any so far. Mixing KMP w/ your existing code is going to be the pain point, at least for me it was. But like I said once your stack is fully KMP its real nice and a breeze.
Leveraging a good Dependency Injection system is going to be key, because in order to gain access to your platform specific code thru interfaces, conforming existing services/code to this shared KMP interface and injecting these instances from each platform is much easier than having to re-write this code in the KMP layer, or dealing w/ the expect/actual dance.Alex Apriamashvili
03/19/2025, 8:33 PMJason
03/19/2025, 9:25 PMAlex Apriamashvili
03/19/2025, 9:36 PMPete Hellyer
03/20/2025, 10:30 AMtouchlab_justin
03/20/2025, 1:02 PMtouchlab_justin
03/20/2025, 1:16 PMkpgalligan
03/20/2025, 2:16 PMOn iOS For KMP there's a lack of proper tootling support (on xcode)
You need to create custom plugins for example to manage building your project, packaging a fat framework that xcode can use and call via swift.
It's a problem as well when switching between device architecture (simulator & iphones).
...It needs to be painless, like flutter or React Native.Flutter and RN need wild, custom plugins to do anything. There's no "proper" tooling support on xcode for those either, because you can't extend Xcode. Our Xcode Kotlin plugin is pushing the boundaries of what's possible with Xcode, because there's very little you can do. Not that the iOS dev experience is good. I wouldn't say it's because it's early days, though, but that there needs to be much more focus on it, and the disparity will have a significant impact on adoption. The big iOC library sounds like a lot. Like you're trying to rebuild everything singlehandedly. Sort of like https://github.com/Ares-Defence-Labs/KmpEssentials 6 months (ish) ago. I've said enough about that, though.