https://kotlinlang.org logo
t

Trey

06/30/2022, 3:16 PM
I have an existing project that we are hoping to switch to use KMP. We have a lot of complex swift code that we would like to include in the shared component. However, rewriting all of that Swift code would be time consuming. The Swift code does stuff like play buffered audio as it is streamed across the network. Is there a trick to reusing that Swift code easily? How have others migrated Swift code into a KMP world?
l

Landry Norris

06/30/2022, 3:22 PM
Kotlin/Native has Obj-C support, so if you mark a Swift class or function with the objc annotation, you can use it from Kotlin. This can allow you to migrate one component at a time.
Note that objc annotation doesn’t work for swift-only features, so no structs.