Flywheel
Flywheel copied to clipboard
Could not cast value of type '' to 'SharedKotlinx_coroutines_coreFlowCollector'
Hi,
I am trying to implement a very simple State in my KMM project and I run into an exception. I don't know if I am doing things correctly, here are some details.
versions
- kotlin : 1.5.30
- flywheel : 1.1.4-RC
- kotlinxCoroutines : 1.5.2-native-mt
use case
I would like to State defined in the shared
kotlin code base and I would like to collect this State in my Swift view model.
On Kotlin side
- I made an
State
and correspondingActions
inshared
(my state has a boolean value modified by the actions) - I have
SDK
kotlin class where I have put aReducer
and aStateReserve
Now on Swift side :
- I have imported flywheel framework and the
CoroutinesHelper.swift
file - I have defined the following state in a ViewModel :
final class MyViewModel: ObservableObject {
let sdk: MySDK
@Published var myState: MyState = MyState(myBoolean = false)
init() {
sdk = MySDK()
sdk.myStateReserve.states.collect(collector: Collector<MyState> { myState in
self.myState = myState
} as! Kotlinx_coroutines_coreFlowCollector) { (unit, error) in
// code executed if the Flow object is completed
}
}
..
}
what is happening
So the first thing different from the sample code you provided is that I am forced to cast Collector<MyState>
to Kotlinx_coroutines_coreFlowCollector
And surely the problem is here as the Exception is the following, calling init()
:
Could not cast value of type '_TtGC6iosApp9CollectorCSo18SharedMyState_' (0x11046c4d0) to 'SharedKotlinx_coroutines_coreFlowCollector' (0x10218ae48).
Am I doing the most simple thing to collect a state in Swift ? If not I am interested to know how I can improve my code ! Thank you so much !
(BTW wiki documentation is great !)
Could you please share the Xcode version & swift version?