Jumping on Bipin’s post above: I want to call a me...
# kotlin-native
y
Jumping on Bipin’s post above: I want to call a method in kotlin native from iOS, which is going to call a method on an interface defined in kotlin and implemented on the iOS side. This method can perform a network call. Rather than the method in the interface using lambdas/closures, I want to use the
suspend
keyword. If you use the suspend keyword, then all methods that call this method also need to be marked with suspend. Which means that the method that is called from the iOS side is marked with suspend. But when I compile the kotlin framework using konan, the methods vanish from the Obj-c framework. Is this because coroutines are experimental? Will this be supported? I’ve got an example project where you can see this happening: https://github.com/yusufcareem/MockKNProject
g
Methods marked as suspend actually compiled in a different way, they have implicit param for continuation and not intendet to be called outside of Kotlin code (on JVM you can do this, but it's not easy, just a hack)
So, what you can do: you need additional non suspend method that can be called outside of Kotlin code and this method should use callbacks/promises API to be interopable with non-kotlin async code
Actual implementation is highly depend on what exactly you want to achieve and use case
So it's sure limitation, you cannot for example override Kotlin interface with suspend function from objc, you need some adapter for that, probably you can just structure your code in a different way and implement such interface with Kotlin class that uses ObjC code and wraps it to coroutines or delegate some calls there
b
Yeah @yusuf3000, I am thinking about same problem may happen in near future in my app.
@gildor do you have any hands on example/repo about same?
g
Example of what? If you provide some particular case we can try to find some solution
b
sure, implementing the stuff, will update you once i have something to showcase
o
Currently suspend functions are not exposed to Swift, as there’s no way to map them. Once Swift will get coroutines -we could reconsider
👍 1
d
Kotlin coroutine to swift coroutine interop....what a glorious future this would be😂