Hello everyone 🙂, I am new to KMP (an Android dev), I want to make my first KMP app and have gotten a bit familiar with KMP folder structure and such. In a modular app (or shared module for that matter), is it possible to call .swift files from iosMain (shared), and use them in ContentView from iosApp (swift ui code for ex) like you can in an Android project?
11/21/2023, 5:51 AM
hmm technically you could find a way to configure gradle properly, but it would fall outside the KMP magic.
KMP projects do have the Foundation library available in iosMain by default. You can add any dependencies that are compatible with Objective-C as well. https://kotlinlang.org/docs/multiplatform-mobile-ios-dependencies.html
So, you shouldn't have to write a swift class in iosMain library just because you want access to some platform specific API. Not sure what your use case is, but there's probably a KMP way to do it without having to write swift outside of your proper ios module
11/21/2023, 6:39 PM
The idea is, have a feature module in my case featurelogin -> for androidMain i would have android ui with compose and for iosMain i would have swift code that i can call from androidApp and iosApp respectively,
commonMain i can share whatever i need to share between these 2 targets
11/21/2023, 9:58 PM
In the app I'm working in - the LoginScreen.kt is written directly into the androidApp module, and the LoginView.swift is written directly into the iosApp module. Both import, inject, and use a LoginService from LoginService.kt in shared/commonMain that handles the API requests to my server, caching locally, etc.
So, I'd recommend keeping any native UI code in the iosApp module. There's no benefit to having it in the shared/iosMain module that I can think of at least