Hi, is it possible to create definitions from the ...
# koin
o
Hi, is it possible to create definitions from the Swift side somehow? I mean something like that:
Copy code
let iosModule = module {
   $0.single { Foo() }
   $0.single(named("BASE_URL")) { Config.BASE_URL }
   $0.factory { Bar(get()) }
}

initKoin {
   modules(iosModule)
}
If it's not possible, are there any workarounds? (On my use case, I need to add BASE_URL from a xcconfig file configuration. Maybe I can find another way to do this but I would like to do what I did on Android side using buildConfig fields)
c
Check the touchlab samples. I think KampKit was the one with such an example. The approach is that you define an object on the Kotlin side, say,
KotlinDependencies
with something like this:
Copy code
getBaz(nameQualifier: String): Baz = getKoin().get<Baz>(named(qualifier))
And on Swift side where you need an instance, you call it like
Copy code
KotlinDependencies.shared.getBaz("BASE_URL")
So you still define all modules on the Kotlin side. But you can still pass dependencies from the Swift side.
o
I'm actually using KaMPKit but it's not what I want. This still requires Baz to be defined in kotlin side. I want to define Baz in Swift side. What you shared is just a way to get a dependency with another function. It doesn't create a definition from swift side, it only injects dependency "to" the swift side.
👍🏽 1
there is an open issue on github about this https://github.com/InsertKoinIO/koin/issues/1292