Hey guys, I used koin and I declared the module like this ```fun initKoin( appDeclaration: Koin...
v
Hey guys, I used koin and I declared the module like this
Copy code
fun initKoin(
    appDeclaration: KoinAppDeclaration = {}
) = startKoin {
    appDeclaration()
    modules(cartModule)
}

fun iosKoin() = initKoin() {}

val cartModule = module {
    single { httpClient() }
    single { KtorCountryApi(get()) }
}
I have KtorCountryApi class
Copy code
class KtorCountryApi(private val httpClient: HttpClient) : NetworkRoute() {
    suspend fun getCountry(): ApiResponse<KtorCountriesResponse> {
       /// api call
    }
}
I am calling the iosKoin() in my .swift file in ios project
My main question is how can I call
KtorCountryApi
in ios with passing httpClient object?
Copy code
func application(_ application: UIApplication,
                     willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        
        KoinKt.iosKoin()
        let ktorCountryApi = KtorCountryApi.init(httpClient:<#T##Ktor_client_coreHttpClient#>)
        return true
    }
t
Add it to your koin declaration. Fill in the bearer auth params for your auth.
v
why should I need to add bearerAuthProvider ?
I am asking how to call
KtorCountryApi
in ios side?
t
Only if you need auth
j
another option is to have
KtorCountryApi
implement
KoinComponent
(example of that in following https://github.com/joreilly/PeopleInSpace/blob/main/common/src/commonMain/kotlin/com/surrus/common/repository/PeopleInSpaceRepository.kt)
v
@John O'Reilly I am seeing your example, you use without paramter in class
j
I guess there's pros and cons for that approach but it at least would allow you to just instantiate
KtorCountryApi
instance in iOS code (if, as in my case, you're not really using Koin within iOS code)
v
okk got it now thanks
j
yes, I'm using
by inject()
in this example
v
now I get it. Thanks