-
Notifications
You must be signed in to change notification settings - Fork 30
Closed
Description
I'm not sure if this is an issue with Kotlin/Native itself but I have a BaseViewModel with generic type T which is used to construct a stateflow:
abstract class BaseViewModel<T: Any>(initialState: T) : KMMViewModel() {
protected val scope = viewModelScope.coroutineScope
private val _state = MutableStateFlow(viewModelScope, initialState)
@NativeCoroutinesState val state = _state.asStateFlow()
protected fun setState(newState: T) {
_state.value = newState
}
}All viewmodels in the project subclass this like so:
class CurrenciesViewModel(
private val getCurrencies: GetCurrencies
) : BaseViewModel<CurrenciesViewModel.State>(State.Idle) {
init {
loadCurrencies()
}
sealed class State {
object Idle : State()
data class Content(
val currencies: Map<String, List<Currency>>,
) : State()
}
}When using this in Xcode, viewModel.state in Swift has a type of Any, which means i have to cast it:
viewModel.state as! CurrenciesViewModel.StateAny idea why?
Thanks in advance
Metadata
Metadata
Assignees
Labels
No labels