Hii , I’m working on a CMP project and I need to u...
# multiplatform
a
Hii , I’m working on a CMP project and I need to use a native iOS SDK that is written 100% in Swift From my understanding, Objective-C based libraries work seamlessly with KMP via CocoaPods due to their compatibility with Kotlin/Native. However, I’m facing trouble integrating this pure Swift library — since Swift-only SDKs don’t expose Objective-C symbols, they don't seem to be directly accessible from the
iosMain
Kotlin code. *What is the recommended or best approach to interop with a pure Swift iOS SDK in a KMP/CMP project?*
s
The most straightforward way is to use dependency inversion and injection. Create interfaces in your common Kotlin code of the functionality that your common Kotlin needs from Swift/iOS. Then implement these interfaces (protocols) in Swift Inject your implementation back into the common Kotlin code as the Swift/iOS impl of that interface that your common Kotlin code will use.
🙌 1
This would require you to write your own Swift wrapper (this wrapper is what implements that interface from common Kotlin code), that then calls this Swift library.
☝️ 1
a
Thanks for the detailed answer Anton I never thought of this approach earlier will try implementing this 👍
e
there are some plugins that can help with objc bridges for swift-only libraries, such as SIKE and spmForKmp (nb. I haven't used either, just seen their existence)
🙌 1
p
If you use Koin you can create an expect module that has actual implementation in each platform. It makes it easier to inject platform implementations in common code. If not using DI you will have to manually expose all your platform implementation factories to common code. The so called platform implementations bridge
🙌 1
z
You'll probably find this useful

https://youtu.be/O0BqoLcRuJI