What is KMP-NativeCoroutines and why use it?
masterKMP-NativeCoroutines is a library designed to bridge Kotlin Coroutines and Swift code in Kotlin Multiplatform (KMP) applications.
It solves two primary limitations of the default Kotlin/Native interoperability:
- Cancellation Support: Standard Kotlin
suspendfunctions are exposed to Swift as functions with completion handlers, which do not support native Swift cancellation. This library enables proper cancellation support. - Generics in Protocols: Because Objective-C does not support generics on protocols, standard Kotlin
Flowinterfaces lose their generic value types when viewed from Swift. This library restores type safety for flows.
Note: While Swift 5.5+ allows calling completion-handler-based functions as async functions, this is only syntactic sugar and does not provide true cancellation support. KMP-NativeCoroutines provides the actual mechanism for cancellation.