icerockdev / moko-mvvm

Model-View-ViewModel architecture components for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
1k stars 95 forks source link

Question: How does the ViewModel component work on iOS? #59

Closed adam-hurwitz closed 3 years ago

adam-hurwitz commented 3 years ago

In the ViewModel with send events to View example, EventsViewModel is implemented for the Android version as an Android component instance of ViewModel.

How does the EventsViewModel work for the iOS version since it cannot implement the same Android component instance of ViewModel? Is there an alternative implementation of ViewModel defined to run for iOS?

Alex009 commented 3 years ago

hi! ViewModel is expect class - https://github.com/icerockdev/moko-mvvm/blob/master/mvvm/src/commonMain/kotlin/dev/icerock/moko/mvvm/viewmodel/ViewModel.kt

actual implementation on android is subclass of android's ViewModel - https://github.com/icerockdev/moko-mvvm/blob/master/mvvm/src/androidMain/kotlin/dev/icerock/moko/mvvm/viewmodel/ViewModel.kt as you already see.

actual implementation on ios is just class - https://github.com/icerockdev/moko-mvvm/blob/master/mvvm/src/iosMain/kotlin/dev/icerock/moko/mvvm/viewmodel/ViewModel.kt

info about expect/actual - https://kotlinlang.org/docs/reference/mpp-connect-to-apis.html

adam-hurwitz commented 3 years ago

I understand the high-level concept now with expect/actual. Thanks for taking the time to share those classes and resources! 🙏🏻