Hi Folks, I need some help related to *`SKIE`*. ...
# touchlab-tools
a
Hi Folks, I need some help related to
SKIE
. So I have an abstract class which looks something like this
Copy code
abstract class BaseViewModel<Event : UiEvent, State : UiState, Effect : UiEffect> : ViewModel() {

 abstract suspend fun handleEvent(event: Event)


    suspend fun setEvent(event: Event) {
        val newEvent = event
        _event.emit(newEvent)
    }

    protected suspend fun setState(reduce: State.() -> State) {
        val newState = currentState.reduce()
        _uiState.emit(newState)
    }

    protected suspend fun setEffect(builder: () -> Effect) {
        val effectValue = builder()
        _effect.emit(effectValue)
    }
}
Then I have a ViewModel which extends this BaseViewModel, something like this:
Copy code
class HomePageViewModel(
    private val fetchFeaturedPlaylistsUseCase: FetchFeaturedPlaylistsUseCase,
    private val fetchFeaturedAlbumsUseCase: FetchFeaturedAlbumsUseCase
) : BaseViewModel<HomePageContract.Event, HomePageContract.State, HomePageContract.Effect>() {

    suspend fun init() {
        subscribeEvents()
    }

    private suspend fun fetchHomePageData() {
        
    }

    override suspend fun handleEvent(event: HomePageContract.Event) {
        when (event) {
            HomePageContract.Event.OnFetchHomePageEvent -> {
                fetchHomePageData()
            }
        }
    }

    override fun onCleared() {
        super.onCleared()
    }
}
Now I have to call
setEffect
which is a
suspend
function. SKIE converts them to Swift async functions. But I'm not able to access setEffect (which comes from base class) on HomePageViewModel but I'm able to call
init()
which is also a
suspend
function but is defined in HomePageViewModel instead of BaseViewModel. Also, I can see an async function for init() but not for setEffect or other suspend function from abstract class (screenshots attached below). Sorry for the long post. Thanks in advance.
Screenshot 2024-01-13 at 2.32.06 AM.png,Screenshot 2024-01-13 at 2.32.20 AM.png
f
Hi! I think the problem is likely that suspend functions of generic classes have to be called using a different syntax: https://skie.touchlab.co/features/suspend#generic-classes
a
Thanks a lot @Filip Dolník. This is what I was missing. Working now as expected.