I have a `StateFlow` that I'm collecting from swif...
# multiplatform
a
I have a
StateFlow
that I'm collecting from swift. It works with a class that inherits from
Kotlinx_coroutines_coreFlowCollector
. But it's rather ugly. Is there are more concise way? Code in 🧵
Copy code
class Collector<T> : Kotlinx_coroutines_coreFlowCollector {
    let callback:(T) -> Void

    init(callback: @escaping (T) -> Void) {
        self.callback = callback
    }
    
    func emit(value: Any?) async throws -> KotlinUnit {
        callback(value as! T)
        return KotlinUnit()
    }
}
Copy code
repo.someStateFlow.collect(
    collector: Collector<TheReturningData> { v in
        print("result \(v)")
    }
) { u, e in
    print("finished")
}
h
j
a
Thanks, I'll take a look!
462 Views