Any examples on how to use channels on iOS? I have...
# coroutines
j
Any examples on how to use channels on iOS? I have a library that expects me to give a
ReceiveChannel
object, but in iOS I cannot instantiate
Kotlinx_coroutines_core_nativeReceiveChannel
because it has no accessible initializers
d
You need to invoke
Channel()
function and send elements to the resulting channel, which is a SendChannel as well as a ReceiveChannel.
Keep in mind that the type of channel may be relevant
j
looks like Channel also doesn’t have any initializers suitable for ios 😞
Copy code
__attribute__((swift_name("Kotlinx_coroutines_core_nativeChannel")))
@protocol Eld_commonKotlinx_coroutines_core_nativeChannel <Eld_commonKotlinx_coroutines_core_nativeSendChannel, Eld_commonKotlinx_coroutines_core_nativeReceiveChannel>
@required
@end;
y
You can convert it to callback in Kotlin code. I think they don't meant to be touched from Swift
I'm not sure if this is the best approach, but here's my pet project. It uses Ktor & SQLDelight to fetch and cache GitHub API. It's quite messy, but it also uses Channel so may be you can grasp some idea. https://github.com/yshrsmz/GitHubKotlinMPPSample
j
I’ll have a look at it, thanks!