Or please let me know if there is a better way of ...
# multiplatform
l
Or please let me know if there is a better way of collecting
Kotlin Flow
from Swift
I know, I know… I refer a lot to the kmm-production-sample on which my apps architecture is based on… but this sample app has a really good architecture and solved a lot of things really nice and pretty (in my opinion).
It bridges Coroutine Flow and SwiftUI State pretty good and is even fully compatible with the old Kotlin/Native memory model.
l
Thank you! I will check it out
a
I like this way too, but how you clear the
Store
object from the memory after destroying the associated activity/view with it? I tested this sample on one screen simple app and it works fine but I wonder if this solution scalable enough to service your needs like ViewModel in android?
s
In my case never. The whole app has a single Store and AppState that represents everything - the whole app state. It’s not like a store / state per view like Android viewmodels.
Also my app is Compose Multiplatform. So there is technically just one view that calls the main composable. And this composable decides on the AppState object what to show.
For the Android version of my app I indeed (ab)use a Android ViewModel, but only to save the current instance of my AppStore object so it survives configuration changes.