It's being called on Kotlin's side through the ViewModel. The ViewModel calls it and exposes it through a CFlow which is just a wrapper of a Flow with an extra watch function that we can use in Objective-C.
Edit: More explanation (I was on a phone earlier and it was hard)
To consume a Flow, you can use collect which has this signature suspend fun Flow<*>.collect(): Unit. Since this is a suspending function, you won't be able to call this in Objective-C. suspend functions' interoperability are still unsupported so we expose a normal watch function that takes a lambda and handles launching the coroutine.
Hi Kurt! Great article but I still have a question:
"Suspending functions aren't compiled to ObjC so we can't use those on iOS" and yet you defined the following function
suspend fun getItems(): List = client.get("url.only.fortest/items")
which is a suspending function. Are they compiled to Objective-C or not?
You can still use Coroutines but only in Kotlin. You won't be able to call them in Objective-C.
So what's the point of the getItems() function if it cannot be called on iOS? Or is it meant to be used only inside the multi-platform code itself?
It's being called on Kotlin's side through the
ViewModel. TheViewModelcalls it and exposes it through aCFlowwhich is just a wrapper of aFlowwith an extrawatchfunction that we can use in Objective-C.Edit: More explanation (I was on a phone earlier and it was hard)
To consume a
Flow, you can usecollectwhich has this signaturesuspend fun Flow<*>.collect(): Unit. Since this is a suspending function, you won't be able to call this in Objective-C.suspendfunctions' interoperability are still unsupported so we expose a normalwatchfunction that takes a lambda and handles launching the coroutine.I take no credit on the
watchfunction. The guys from Jetbrains did a good job on it. github.com/JetBrains/kotlinconf-ap...