1 year ago
#304008
Afonso
Best practices for handling platform exclusive features in KMM
I have an existing iOS app and I'm trying out KMM. Ideally, when launched, the app would be available both for Android and iOS, but I'd like for existing iOS users not to lose their current content.
I started building a MigratorService
in iosMain
, as all it's going to be doing is dealing with platform-specific models, but then I didn't have a way to call it from commonMain
. So I either:
- Move all the code I've done in
iosMain
tocommonMain
. Although there is the potential risk of exposing old iOS related code to Android, in reality this would never happen since the migration only happens for iOS. - Create an expect
MigratorService
in commonMain, with the actual implementation being oniosMain
. But this approach implies also adding a completeno-op
version ofMigratorService
inandroidMain
. Which is exposing an API that doesn't really do what is expected.
Which one would be considered the best practice in KMM and why? Or is there another alternative to tackle these situations?
Cheers
kotlin-multiplatform
kmm
0 Answers
Your Answer