touchlab / KaMPKit

KaMP Kit by Touchlab. A collection of code & tools designed to get your mobile team started quickly w/Kotlin Multiplatform
https://touchlab.co/
Apache License 2.0
2.2k stars 199 forks source link

Koin modules inside iOS code #166

Closed BulatMukhutdinov closed 2 years ago

BulatMukhutdinov commented 3 years ago

You provided an example of how to fetch and use objects from a shared module using koin. But could you also provide an example of how to create koin modules directly inside iOS code on Swift and then fetch these dependenceis?

Thanks in advance

russhwolf commented 3 years ago

Here's an old commit that tried configure Koin from Swift. It's complicated because Koin's internals will try to pull out a KClass and you can't do that for Objective-C types, so I had to cast things to Any and use qualifiers to disambiguate instead. We decided this wasn't worth it which is why we instead have the current configuration where Swift dependencies are passed as function arguments and the Koin configuration happens on the Kotlin side.

BulatMukhutdinov commented 3 years ago

I see, thanks. Then probably you can provide an example of what is the best way to provide dependencies in swift code? For example, how to provide a view model (which has dependencies from koin) created inside swift code to view.

kpgalligan commented 2 years ago

I'd probably write a basic factory object that's easy to call from Swift. Interacting with Koin directly will be clumsy because of the generics, etc. Easier to write concrete Kotlin wrappers and call them.