DEV Community

Discussion on: Maximizing Code Sharing between Android and iOS with Kotlin Multiplatform

 
kuuurt profile image
Kurt Renzo Acosta • Edited

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.

I take no credit on the watch function. The guys from Jetbrains did a good job on it. github.com/JetBrains/kotlinconf-ap...