Karthick
03/17/2024, 4:49 PMandroidx.lifecycle.ViewModel
. But the problem was that i created these in shared
module and when i used shared
module in another module and created FeatureViewModel in commonMain, it is giving error of Cannot access 'androidx.lifecycle.ViewModel' which is a supertype of 'FeatureViewModel'. Check your module classpath for missing or conflicting dependencies
.
Why common code worrying about actual implementations?Karthick
03/17/2024, 4:52 PMexpect open class ViewModel() {
protected val viewModelScope: CoroutineScope
protected fun onCleared()
}
actual open class ViewModel : AndroidViewModel() {
actual val viewModelScope: CoroutineScope = AndroidViewModelScope
actual override fun onCleared() {
super.onCleared()
}
}
Karthick
03/18/2024, 5:12 AMmohamed rejeb
03/18/2024, 5:23 AMclass ViewModel(
val viewModelScope: CoroutineScope,
) {
fun onCleared() {}
}
androidMain:
class AndroidViewModel(): ViewModel() {
val viewModel = ViewModel(viewModelScope = viewModelScope)
override fun onCleared() {
super.onCleared()
viewModel.onCleared()
}
}
mohamed rejeb
03/18/2024, 5:36 AM