Where should I keep the viewModel? In common code ...
# multiplatform
h
Where should I keep the viewModel? In common code or platform spesific?
s
Can be either. Your choice
You'll have to abstract out a common expect (or interface) so that it works on both platforms if you do decide to share it.
k
We tend to keep it in common code, and then have expect / actuals for the
ViewModel
itself, so we can use the
viewModelScope
for android and simulate it for iOS. Like Anton said though it could be either
a
@Kevin S do you wrap the viewModel in
ObservableObject
on the iOS side??
k
a
But is the
ObservableObject
avoidable? Where by we use the common viewModel in SwiftUI like compose does?
r
I am currently working on something for that (initial release coming soon): https://github.com/rickclephas/KMM-ViewModel It’s just removing the boilerplate, in the end it still uses an observable object since that’s needed for SwiftUI.
h
@Rick Clephas it looks awesome already.