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.
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
. TheViewModel
calls it and exposes it through aCFlow
which is just a wrapper of aFlow
with an extrawatch
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 usecollect
which has this signaturesuspend 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 normalwatch
function that takes a lambda and handles launching the coroutine.I take no credit on the
watch
function. The guys from Jetbrains did a good job on it. github.com/JetBrains/kotlinconf-ap...